Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142646

Can message passing be used to detect if another extension is enabled?

$
0
0

I would like to check if another extension is enabled. I understand Management API can be used to check if another extension is enabled (Detect if another Chrome Extension is installed). However, I try to request for minimum permission and therefore I would like to ask if I can use message passing.

Extension A

let extPort = chrome.runtime.connect(ExtB);
extPort.postMessage({from: "ExtA", fn: "greeting"});
extPort.onMessage.addListener(function(message, sender) {
    if ((message.from == "ExtB") && (message.fn == "greeting")) {
        console.log("Ext B is enabled");
    }
});

Extension B

chrome.runtime.onConnectExternal.addListener(function(port) {
    port.onMessage.addListener(function(message, sender) {
        if ((message.from == "ExtA") && (message.fn == "greeting")) {
                port.postMessage({from: "ExtB", fn: "greeting"});
        }
    });
});

This method works fine if Extension B is enabled but an error message is shown if Extension B is NOT enabled. Any way to handle this error message?

Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

Viewing all articles
Browse latest Browse all 142646

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>