无法在“DedicatedWorkerGlobalScope"上执行“postMessage":无法将提供的值转换为序列 [英] Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': The provided value cannot be converted to a sequence

查看:26
本文介绍了无法在“DedicatedWorkerGlobalScope"上执行“postMessage":无法将提供的值转换为序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误

未捕获的类型错误:无法执行 'postMessage''DedicatedWorkerGlobalScope':无法转换提供的值到一个序列.

Uncaught TypeError: Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': The provided value cannot be converted to a sequence.

在网络工作者的这一行:

on this line in a webworker:

postMessage("hi", "http://localhost:8000");

(实际上,这就是网络工作者的全部).

(in fact, that is the entirety of the webworker).

基本文件包含:

var myWorker = new Worker("test.js");
myWorker.onmessage = function (e) {
    console.log('Message received from worker');
};

我不确定它抱怨的是哪个值,也不确定将其转换为序列"意味着什么.

I'm not sure which value it's complaining about and I'm not sure what it means for it to be converted to a "sequence".

推荐答案

发布消息的目的地是隐式的(从内部调用时,函数正在被调用的工作者对象,或创建工作者的脚本)工人.所以你应该使用:

The destination for the posted message is implicit (either the worker object the function is being called on, or the script that created the worker, when called from within the worker. So you should just use:

postMessage("hi");

参见:MDN 上的 postMessage

如果它对像我这样因无关原因遇到此问题的其他人有用,我正在这样做:

In case it's useful to others like myself who run into this problem for unrelated reasons, I was doing:

postMessage("type", value)

当我打算这样做时:

postMessage(["type", value])

这篇关于无法在“DedicatedWorkerGlobalScope"上执行“postMessage":无法将提供的值转换为序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆