Uncaught ReferenceError: importScripts is not defined

后端 未结 3 1657
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-14 14:56

Why do I keep getting this error?

I should be able to use this global function right?

http://www.html5rocks.com/en/tutorials/workers/basics/

I\'m usi

3条回答
  •  [愿得一人]
    2020-12-14 15:51

    I encountered this error as well. In my case, it is because I am testing the code using Karma/Jasmine. Due to the test framework, the worker.js file is loaded by main thread as well.

    I avoided this error by wrappig the worker.js file with:

        if( 'undefined' === typeof window){
           importScripts('workerscript2.js');
        ...
        }
    

    Please refer to the comment below by Rob, which offers an alternative solution.

提交回复
热议问题