src/BackgroundHandler.js
/**
     * Handle a new incoming connection
     * 
     * @param {chrome.runtime.Port} port The newly created connection to a content script.
     */
Handle a new incoming connection

@param {chrome.runtime.Port} port The newly created connection to a content script.
Handle a new incoming connection @param { chrome . runtime . Port } port The newly created connection to a content script .
handleNewConnection(port) {
        if (!this.isInternalConnection(port)) return;
        let scriptId = "";
        if (this.isTabAgnostic(port)) {
            scriptId = port.name.substr(CONNECTION_PREFIX_NOTAB.length);
        }
        else {
            scriptId = port.name.substr(CONNECTION_PREFIX.length);
            let tabId = port.sender.tab.id;
            scriptId += `-${tabId}`;
        }
        if (this.scriptConnections.get(scriptId)) {
            port.disconnect();
            return this.handleError(ERRORS.ID_TAKEN, scriptId);
        }
        let connectionOptions = { hasTabId: false };
        let connection = new Connection(port, this.exposedData, connectionOptions);
        connection.addListener("disconnect", () => this.disconnectScript(scriptId) );
        this.scriptConnections.set(scriptId, connection);
    }
handleNewConnection ( port ) { if ( ! this . isInternalConnection ( port ) ) return ; let scriptId = "" ; if ( this . isTabAgnostic ( port ) ) { scriptId = port . name . substr ( CONNECTION_PREFIX_NOTAB . length ) ; } else { scriptId = port . name . substr ( CONNECTION_PREFIX . length ) ; let tabId = port . sender . tab . id ; scriptId += ` ${ tabId } ` ; } if ( this . scriptConnections . get ( scriptId ) ) { port . disconnect ( ) ; return this . handleError ( ERRORS . ID_TAKEN , scriptId ) ; } let connectionOptions = { hasTabId : false } ; let connection = new Connection ( port , this . exposedData , connectionOptions ) ; connection . addListener ( "disconnect" , ( ) => this . disconnectScript ( scriptId ) ) ; this . scriptConnections . set ( scriptId , connection ) ; }
Handle a new incoming connection
Handle a new incoming connection
// In the background script, there is no tab-id associated