HTML5 Web Worker 错误“未捕获的语法错误:参数不足”当使用多个 postMessage 调用时
我有一个 Web Worker,它发出大约 30 个 AJAX 请求,在每个请求之后,它使用 postMessage 向 UI 发送一条消息来记录进度。 例如:
postMessage({type: "progress", name: "customers", message: "Success" }).
大约 10-20 个请求(并不总是相同的数量)后,会出现以下错误:
未捕获的语法错误:没有足够的参数。
如果我删除 postMessage 调用,一切都会正常工作,如果我添加额外的 postMessage 调用,网络工作人员会在更少的请求后给出错误。
它似乎还取决于数据的类型,如果 postMessage 调用包含 JSON 对象而不是字符串,则 Web Worker 会更快死亡。
有谁知道为什么会发生这种情况?
I have a single web worker which makes about 30 AJAX requests and after each request it sends a message to the UI using postMessage to log the progress.
For example:
postMessage({type: "progress", name: "customers", message: "Success" }).
After about 10-20 requests (not always the same number), the following error appears:
Uncaught SyntaxError: Not enough arguments.
If I remove the postMessage calls, everything works fine, and if I add additional postMessage calls, the web worker gives the error after even fewer requests.
It seems to also depend on the type of data, the web worker dies sooner if the postMessage calls contain JSON objects rather than strings.
Does anyone know why this happens ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,至少在我的情况下,如果在短时间内(毫秒)多次调用 postMessage 就会失败,
每 500 毫秒调用 postMessage 就解决了我的问题。
It turns out that, at least in my case, postMessage fails if it is called multiple times in a short amount of time (milliseconds)
Calling postMessage only every 500 milliseconds solved the issue for me.