When a content script run in a non-tab page/frame (e.g. sidebar or extension popup), and opens an extension port using runtime.connect, then the extension (e.g. background page) can receive the port and messages sent FROM the content script, but the content script cannot receive messages sent TO the content script. STR: 1. Load attached extension, which loads example.com in a sidebar and loads a content script in it. 2. In the extension sidebar, click on the "runtime.connect()" button. 3. Look at the sidebar Expected result: - [CS] ... opening port - [CS] ... Received message: Initial message from BG Actual result: - [CS] ... opening port - (no "Received message") That is because the extension message routing logic relies on being able to identify the recipient via its sender. When such a sender is missing, then the following will fail to find a message manager and the message is dropped: https://searchfox.org/mozilla-central/rev/721842eed881c7fcdccb9ec0fe79e4e6d4e46604/toolkit/components/extensions/ExtensionParent.jsm#356-359,450-492 This could easily be fixed by falling back to identifying a target by its context ID, as ParentAPIManager in ExtensionParent.jsm keeps a mapping from extension ID+context ID to ProxyContextParent: https://searchfox.org/mozilla-central/rev/721842eed881c7fcdccb9ec0fe79e4e6d4e46604/toolkit/components/extensions/ExtensionParent.jsm#755 I found this bug because a user reported that an add-on was broken when they used it with Side View ( https://testpilot.firefox.com/experiments/side-view/ ). Sideview uses sidebars, and the extension used runtime.connect to establish a communication channel with the background page.
Fixes bug 1488105 and adds two new test files: - browser test to test ping-pong from background page, sidebar and browserAction. - xpcshell test with same test logic, mainly for Android test coverage. The test uses uses contentScripts.register instead of the manifest file to also have test coverage for contentScripts.register + child frames in the background page. These tests serve as a regression test for bug 1488105 and bug 1463074.
Comment on attachment 9007212 [details] Bug 1488105 - Fix routing of extension port messages to non-tab contexts Shane Caraveo (:mixedpuppy) has approved the revision.
Attachment #9007212 - Flags: review+
Pushed by email@example.com: https://hg.mozilla.org/integration/autoland/rev/4f80e37f27e3 Fix routing of extension port messages to non-tab contexts r=mixedpuppy
You need to log in before you can comment on or make changes to this bug.