Content scripts running in non-web page context on Firefox
Environment
- Browser and full version: Firefox 98.0b2
- Extension using this toolkit: test-mv2
- Commit hash: e8672fe5
Steps to reproduce
- Add the line
console.log("hello", sender);
after this line. - Build and install test extension.
- Open developer tools for background page.
Actual behavior
The JavaScript console shows the log item as hello Object { contextId: 274877907199, id: "500dbce84ac70b65524490c3c571917fb423f41d@temporary-addon", envType: "content_child", url: "about:blank" }
.
Expected behavior
The JavaScript console doesn't show the log item.
Further information
The underlying problem appears to be that Firefox mistakenly runs the extension's content scripts not only on web pages, but also in the context of its developer tools, as indicated by the sender ID being the extension's own ID.
This issue was first encountered at https://gitlab.com/eyeo/adblockplus/abpui/adblockplusui/-/issues/1082, but as far as the SDK is concerned, it doesn't appear to be causing any problems so far. That being said, since we don't expect content scripts to run in this context, this can lead to problems in the future. For example, as seen in the linked issue, it already causes an error to be thrown in the Adblock Plus background page, because it's unable to handle one of the messages sent by its content scripts from that context.