[英]Shared Worker not being loaded by Chrome (unless in incognito mode)
edit 编辑
Renaming the shared-worker.js
file to anything else, eg shared-worker-new.js
, seems to fix the issue. 将
shared-worker.js
文件重命名为其他任何文件,例如shared-worker-new.js
,似乎可以解决此问题。 I have tried emptying the cache, restarting the browser and doing hard-reloads but shared-worker.js
just doesn't want to work. 我尝试清空缓存,重新启动浏览器并进行硬重装,但是
shared-worker.js
只是不想工作。 The new worker file doesn't seem to suffer from caching issues. 新的工作文件似乎没有出现缓存问题。 Changes to the file are instantly applied after a reload.
重新加载后,对文件的更改将立即应用。 Does anyone have any ideas as to why I can't use
shared-worker.js
? 有谁对我为什么不能使用
shared-worker.js
有任何想法?
/edit /编辑
I can't seem to load my Shared Worker in Google Chrome (67.0.3396.99). 我似乎无法在Google Chrome(67.0.3396.99)中加载共享工作器。 However when I switch to incognito mode it does work.
但是,当我切换到隐身模式时,它确实可以工作。 Firefox (61.0.1) works fine in both regular and private mode.
Firefox(61.0.1)在常规模式和私有模式下均可正常运行。 I've already tried disabling my browser plugins but that didn't work either.
我已经尝试过禁用浏览器插件,但是那也不起作用。
I have 3 files (in the same directory): index.html
, app.js
and shared-worker.js
. 我有3个文件(在同一目录中):
index.html
, app.js
和shared-worker.js
。
index.html index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Shared Worker Example</title>
</head>
<body>
<script src="app.js"></script>
</body>
</html>
app.js app.js
var worker = new SharedWorker('./shared-worker.js');
worker.port.onmessage = function(message) {
console.log('message from the shared worker:', message.data);
};
worker.port.start();
worker.port.postMessage('Hello worker');
shared-worker.js shared-worker.js
self.onconnect = function(connect) {
var port = connect.ports[0];
port.addEventListener('message', function(message) {
port.postMessage(`I have received "${message.data}"`);
});
port.start();
};
I am running the app via php -S localhost:9000
我正在通过
php -S localhost:9000
运行该应用程序
message from the shared worker: I have received "Hello worker"
. message from the shared worker: I have received "Hello worker"
: message from the shared worker: I have received "Hello worker"
。 message from the shared worker: I have received "Hello worker"
. message from the shared worker: I have received "Hello worker"
。 I don't see the worker listed under Sources/Threads in the developer tools however when I load the shared-worker as a regular worker, ie var worker = new Worker('shared-worker.js');
我没有在开发人员工具的“源/线程”下看到该工作程序,但是当我将共享工作程序加载为常规工作程序时,即
var worker = new Worker('shared-worker.js');
, it does appear. ,它确实出现。
Why can't I load a Shared Worker in chrome, does anyone have any idea what is going on? 为什么我不能在chrome中加载共享工作器,有人知道发生了什么吗?
Thanks a gazillion in advance! 在此先感谢您!
DOH - Turns out my devtools were likely to be the cause of the problem ¯\\_(ツ)_/¯. DOH-事实证明,我的devtool可能是造成问题的原因。 It was stopping the execution of my shared worker.
它停止了我共享工作者的执行。 If anyone else is running into this problem, make sure you have closed ALL the tabs in the session that use the shared worker and that your debugger is not pausing the execution.
如果其他任何人都遇到此问题,请确保关闭了会话中使用共享工作程序的所有选项卡,并且调试器没有暂停执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.