port.onMessage not fired in content scripts in non-tabs (sidebar, extension popup views)

RESOLVED FIXED in Firefox 64


6 months ago
5 months ago


(Reporter: robwu, Assigned: robwu)


(Depends on: 1 bug)

Bug Flags:
qe-verify -

Firefox Tracking Flags

(firefox64 fixed)



(2 attachments)



6 months ago
Created attachment 9005919 [details]

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.

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:

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:

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.
Depends on: 1318532

Comment 1

5 months ago
Created attachment 9007212 [details]
Bug 1488105 - Fix routing of extension port messages to non-tab contexts

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+

Comment 3

5 months ago
Pushed by rob@robwu.nl:
Fix routing of extension port messages to non-tab contexts r=mixedpuppy

Comment 4

5 months ago
Last Resolved: 5 months ago
status-firefox64: --- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla64


5 months ago
Flags: qe-verify-
You need to log in before you can comment on or make changes to this bug.