Firefox Quantum SharedWorker无法正常工作 [英] Firefox Quantum SharedWorker not work

查看:102
本文介绍了Firefox Quantum SharedWorker无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Chrome和Firefox< 57中,它可以工作,但在Firefox Quantum中不起作用.

In Chrome and Firefox <57 it works, but in Firefox Quantum doesn't work.

目标是将消息发送到浏览器中的另一个选项卡.

The goal is to send a message to another tab in the browser.

在填写文本输入并单击发送"按钮时,浏览器中的另一个选项卡应在浏览器控制台中编写消息.

When filling in the text input and clicking the send button, the other tab in the browser should write the message in the browser console.

html文件:

<script type="text/javascript">
    const myWorker = new SharedWorker( "sharedWorkerChat.js" );
    const port = myWorker.port;

    port.addEventListener( "message", function( e ) {
        console.log( e.data );
    }, false );

    port.start();

    function postMessage() {
        const value = document.getElementById( "input" ).value;
        console.log( value );
        port.postMessage( value );
    }
</script>


<input type="text" id="input" />

<button onclick="postMessage()"> Send </button>

sharedWorkerChat.js

sharedWorkerChat.js

var m;

var instances = [];
self.addEventListener( "connect", function ( e ) {
    var port = e.ports[ 0 ];
    instancias.push( port );

    port.addEventListener( "message", function ( message ) {
        m = message.data;
        instances.forEach( function( p ) {
            p.postMessage( m );
        });
    }, false );

    port.start();
}, false);

推荐答案

我刚刚遇到了同样的问题,显然Firefox Quantum默认启用了多处理功能,并且尚不支持SharedWorkers.

I just came across the same problem, apparently Firefox Quantum enables the multiprocessing functionality by default and it doesn't yet support SharedWorkers.

要检查是否启用了多处理功能,请在地址栏中输入 about:debugging#workers ,如果该功能处于活动状态,则应在页面顶部看到一个关于SharedWorkers的黄色警告.

To check if you have multiprocessing enable type about:debugging#workers in your address bar, if it is active you should see a yellow warning about SharedWorkers at the top of the page.

您可以通过点击该警告上的链接来禁用此功能.

You can disable this functionality by following the link on that warning.

这篇关于Firefox Quantum SharedWorker无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆