Webworker served from the local filesystem not working

╄→гoц情女王★ 提交于 2019-12-24 07:52:56

问题


I am trying to make the web worker example from MDN to work when it is not served from a server but opened directly open from my local filesystem (via a via file:// URL)

The example works fine when served from Apache at http://localhost/1/simple-web-worker-gh-pages/index.html but it doesn't when it is read locally at file:///var/www/html/1/simple-web-worker-gh-pages/index.html

The developer console shows that messages are posted but there is no answer from the worker. (I tried both Firefox and Chromium.)

How can I make it to work ?

(There's a similar question failed to load script - Webworker (PDF.JS) , but my problem is different, as I don't see a "Failed to load script" error.)


回答1:


Avoid developing using file:/// - you'll waste time debugging, as not everything is supposed to work there.

In case of Worker() in Firefox, this was supported a year ago, but was apparently disabled in Firefox 68.

See Firefox 68: local files now treated as cross-origin; is there a way to override? - if you set privacy.file_unique_origin to false in about:config, the example should work.



来源:https://stackoverflow.com/questions/57442629/webworker-served-from-the-local-filesystem-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!