Firefox Quantum SharedWorker not work

╄→гoц情女王★ 提交于 2019-12-29 07:17:11

问题


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 file:

<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

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);

回答1:


I just came across the same problem, apparently Firefox Quantum enables the multiprocessing functionality by default and it doesn't yet support 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.



来源:https://stackoverflow.com/questions/47414543/firefox-quantum-sharedworker-not-work

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