JavaScript: More robust condition for outlining

As per @SLaks' comment at #528, here is a more robust condition for outlining