Added some extra checks to make sure we're in a Web Worker.