简体   繁体   English

Chrome无法加载Shared Worker(除非在隐身模式下)

[英]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.htmlapp.jsshared-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运行该应用程序

  • In Firefox the console outputs the following: message from the shared worker: I have received "Hello worker" . 在Firefox中,控制台输出以下message from the shared worker: I have received "Hello worker"message from the shared worker: I have received "Hello worker"
  • In an incognito Chrome tab I get the following output: message from the shared worker: I have received "Hello worker" . 在一个隐身的 Chrome标签中,我得到以下输出: message from the shared worker: I have received "Hello worker"
  • In a regular Chrome tab I get no output at all. 在常规的Chrome选项卡中,我根本没有输出。

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.

相关问题 chrome隐身模式下的LocalStorage - LocalStorage in chrome Incognito Mode jQuery侦听器在隐身模式Chrome中间歇性工作 - Jquery listener works intermittently in incognito mode chrome Javascript 效果仅适用于“隐身模式”(Chrome) - Javascript effect works in "Incognito mode" only (Chrome) Firebase通知在Chrome隐身模式下无效 - Firebase notification are not working in chrome incognito mode 在隐身模式下使用chrome.browsingData.remove() - Using chrome.browsingData.remove() in incognito mode 在Chrome隐身模式下设置了Adobe Target PCID,但在普通模式下丢失了 - Adobe Target PCID set in Chrome Incognito Mode But Missing in Normal MOde 如何在隐身模式下为Chrome扩展程序启用pageAction图标? - How to enable a pageAction icon for a chrome extension in incognito mode? 是否可以在当前标签页中模拟隐身模式? (chrome扩展名) - Is it possible to simulate incognito mode in current tab? (chrome extension) socket.emit无法在移动设备上运行(但它可以在隐身模式下运行) - socket.emit is not working in mobile chrome (but it works in incognito mode) Chrome扩展程序以隐身模式在另一个窗口中打开URL - Chrome Extension to open URL in another window in Incognito mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM