Security

The following note only applies if and only if, you will be sending/receiving messages to/from window contexts. There's no security concern if you will be only working with content-script, background, popup, options, or devtools scope, which is the default setting.

window context(s) in tab A get unlocked the moment you call allowWindowMessaging(namespace) somewhere in your extension's content script(s) that's also loaded in tab A.

Unlike chrome.runtime.sendMessage and chrome.runtime.connect, which requires extension's manifest to specify sites allowed to talk with the extension, webext-bridge has no such measure by design, which means any webpage whether you intended or not, can do sendMessage(msgId, data, 'background') or something similar that produces same effect, as long as it uses same protocol used by webext-bridge and namespace set to same as yours.

So to be safe, if you will be interacting with window contexts, treat webext-bridge as you would treat window.postMessage API. Before you call allowWindowMessaging, check if that page's window.location.origin is something you expect already.

If you plan on having something critical, always verify the sender before responding:

Verifying an endpoint before responding

import { onMessage, isInternalEndpoint } from "webext-bridge/background";

onMessage("getUserBrowsingHistory", (message) => {
    const { data, sender } = message;

    // Respond only if request is from 'devtools', 'content-script', 'popup', 'options', or 'background' endpoint
    if (isInternalEndpoint(sender)) {
        const { range } = data;
        return getHistory(range);
    }
});