Open Bug 1300234 Opened 8 years ago Updated 9 months ago

addListener methods should return a promise

Categories

(WebExtensions :: General, defect, P3)

51 Branch
defect

Tracking

(Not tracked)

People

(Reporter: robwu, Unassigned)

References

Details

(Whiteboard: triaged)

Event registration with proxied APIs is asynchronous. This leads to missing events when a WebExtension API is used with other APIs that would trigger the event.

In the next example, I expect an onRemoved event, but I did not receive any, probably because window.close() uses higher-priority IPC than the WebExtensions event implementation.

var win = window.open("http://example.com");
// Wait until the window opens and then run the following:
browser.tabs.onRemoved(tabId => console.log("Removed tab" + tabId));
win.close();
This test: http://searchfox.org/mozilla-central/rev/950e13cca1fda6507dc53c243295044e8eda4493/toolkit/components/extensions/test/mochitest/test_ext_tab_teardown.html#119
fails because the (extension) tab is hosted in the main process, and calling window.close()
synchronously triggers http://searchfox.org/mozilla-central/rev/950e13cca1fda6507dc53c243295044e8eda4493/browser/base/content/tabbrowser.xml#4694

... so the tab is closed before the asynchronous tabs.onRemoved.addListener event has had a chance to run.
Priority: -- → P3
Whiteboard: triaged
Bug 1343940 is another instance of this bug.
See Also: → 1343940
Component: WebExtensions: Untriaged → WebExtensions: General
Summary: Events in ChildAPIManager + ParentAPIManager are out of sync with non-WebExtension APIs → addListener methods should return a promise
Product: Toolkit → WebExtensions
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.