从本地文件系统提供服务的Webworker无法正常工作 [英] Webworker served from the local filesystem not working
问题描述
我正在尝试使MDN中的网络工作者示例能够正常工作不是从服务器提供服务,而是从本地文件系统直接打开(通过via file://URL)打开
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)
当从Apache通过 http://提供服务时,该示例运行正常本地主机/1/simple-web-worker-gh-pages/index.html 但是在文件:///var/www/html/1/simple-web-worker-gh-pages/index.html
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
开发人员控制台显示消息已发布,但工作人员没有任何答复. (我尝试了Firefox和Chromium.)
The developer console shows that messages are posted but there is no answer from the worker. (I tried both Firefox and Chromium.)
我如何使其起作用?
(存在类似的问题无法加载脚本-Webworker(PDF.JS ),但是我的问题有所不同,因为我没有看到无法加载脚本"错误.)
(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.)
推荐答案
避免使用file:///进行开发-您会浪费时间进行调试,因为并非所有功能都应该在那里工作.
Avoid developing using file:/// - you'll waste time debugging, as not everything is supposed to work there.
如果是Firefox中的Worker()
,则是一年前得到支持,但显然在Firefox 68中已禁用.
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.
这篇关于从本地文件系统提供服务的Webworker无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!