Troubleshooting

With all the moving parts, it's easy to run into issues. Here's a few common mistakes.

Doesn't work?

If window contexts are not part of the extension, webext-bridge works out of the box for messaging between devtools <-> background <-> content-script(s).

If even that is not working, it's likely that webext-bridge hasn't been loaded in background page of your extension, which is used by webext-bridge as a relay. If you don't need a background page for yourself, here's bare minimum to get webext-bridge going.

First, add a background.js file within your extension. In the background script, add the following code:

background.js

import "webext-bridge/background";

Next, include that file within your manifest:

manifest.json

{
    "background": {
        "scripts": ["path/to/transpiled/background.js"]
    }
}

You now have a simple background script within your extension that the webext-bridge can use as a staging ground for communicating messages.

Can't send messages to window?

Sending or receiving messages from or to window requires you to open the messaging gateway in content script(s) for that particular tab.

Call allowWindowMessaging(<namespaceA: string>) in any of your content script(s) in that tab and call setNamespace(<namespaceB: string>) in the script loaded in top frame i.e the window context. Make sure that namespaceA === namespaceB.

If you're doing this, read the security section