Closed Bug 1488105 Opened 4 years ago Closed 4 years ago

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


(WebExtensions :: General, defect)

Not set


(firefox64 fixed)

Tracking Status
firefox64 --- fixed


(Reporter: robwu, Assigned: robwu)


(Depends on 1 open bug)



(2 files)

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 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:,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:

I found this bug because a user reported that an add-on was broken when they used it with Side View ( ). Sideview uses sidebars, and the extension used runtime.connect to establish a communication channel with the background page.
Depends on: 1318532
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
Fix routing of extension port messages to non-tab contexts r=mixedpuppy
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla64
Flags: qe-verify-
You need to log in before you can comment on or make changes to this bug.