Web工作者在mac safari上触发异常

Sha*_*dse 10 javascript safari web-worker

我正在创建一个Web工作者时遇到以下异常.检查我的代码片段

    var temp = new Worker('/file.js')
    try{
    temp.postMessage('msg')
    }
    catch(e){
     console.error(e)
     }
Run Code Online (Sandbox Code Playgroud)

异常是"TypeError:值不是序列"

kro*_*eck 0

我不确定这有多么相关,但是我们console.*在任何启用了 WebDriver 扩展的 Safari 实例上遇到了调用问题。我怀疑它与 WebDriver 收集控制台日志的方式有关,它以某种方式覆盖默认实现,从而抛出TypeError.

对于单元测试,我们的解决方案是使用 jasmine 应用我们自己的模拟。类似的解决方案可能会对您有所帮助。

beforeEach(() => {
  if (window.navigator.userAgent.indexOf('Safari') > -1) {
    spyOn(console, 'log').and.stub();
    spyOn(console, 'info').and.stub();
    spyOn(console, 'warn').and.stub();
    spyOn(console, 'debug').and.stub();
    spyOn(console, 'error').and.stub();
  }
});
Run Code Online (Sandbox Code Playgroud)