Any standard mechanism for detecting if a JavaScript is executing as a WebWorker?

后端 未结 5 1681
遇见更好的自我
遇见更好的自我 2020-12-14 19:01

A WebWorker executes with a scope completely separate from the \'window\' context of traditional JavaScript. Is there a standard way for a script to determine if it is, its

5条回答
  •  温柔的废话
    2020-12-14 19:28

    This worked for me

      if (self.document) {
        console.log('We are calculating Primes in Main Thread');
      } else {
        console.log('We are calculating Primes in Worker Thread');
      }
    

提交回复
热议问题