Closed Bug 1711570 Opened 3 years ago Closed 2 years ago

support promises on chrome namespace

Categories

(WebExtensions :: General, enhancement, P3)

enhancement
Points:
3

Tracking

(firefox106 fixed)

RESOLVED FIXED
106 Branch
Tracking Status
firefox106 --- fixed

People

(Reporter: mixedpuppy, Assigned: mixedpuppy)

References

(Blocks 1 open bug)

Details

(Keywords: dev-doc-complete, Whiteboard: mv3:m3 [mv3-m3] )

Attachments

(1 file)

chrome namespace should support promises just like browser namespace

We should not only check whether APIs return a Promise, but also check whether the behavior is consistent when a callback is used.
This unit test here is particularly interesting: https://searchfox.org/mozilla-central/rev/0e8b28fb355afd2fcc69d34e8ed66bbabf59a59a/toolkit/components/extensions/test/mochitest/test_ext_sendmessage_no_receiver.html#55-68

  • The comment + TODO can be removed since we now wish for chrome. to return a Promise.
  • The second part of the test verifies that the chrome.runtime.sendMessage(msg, callback) signature doesn't return anything. If we want to unconditionally return a Promise, then the test should be adjusted.
See Also: → 1296896

In part6 of bug 1688040, browser and chrome are aliases of each other, so if we move to that, this bug will be resolved almost for free (after fixing up tests like the one I mentioned before).

See Also: → 1688040

(In reply to Rob Wu [:robwu] from comment #2)

  • The second part of the test verifies that the chrome.runtime.sendMessage(msg, callback) signature doesn't return anything. If we want to unconditionally return a Promise, then the test should be adjusted.

My understanding was that with chrome, if a callback is used, promises were not returned. I'm not sure it matters that much if we did unconditionally return a promise, in that case a chrome extension should still port to firefox just fine.

(In reply to Shane Caraveo (:mixedpuppy) from comment #4)

(In reply to Rob Wu [:robwu] from comment #2)

  • The second part of the test verifies that the chrome.runtime.sendMessage(msg, callback) signature doesn't return anything. If we want to unconditionally return a Promise, then the test should be adjusted.

My understanding was that with chrome, if a callback is used, promises were not returned.

I just checked in Chromium 90; when a callback is passed, no promise is returned. This is consistent with how Firefox already behaves in the browser. namespace. This only works in manifest v3, in manifest v2 promises are not supported.

I'm not sure it matters that much if we did unconditionally return a promise, in that case a chrome extension should still port to firefox just fine.

Whether to return a promise even if a callback is passed does matter, because it's an observable difference that can result in a difference in behavior.

Whiteboard: mv3:m3 → mv3:m3 [mv3-m3]
Points: --- → 3
Whiteboard: mv3:m3 [mv3-m3] → mv3:m3 [mv3-m3]
Assignee: nobody → mixedpuppy
Status: NEW → ASSIGNED
Pushed by scaraveo@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/caff3cab943c
allow promises with chrome namespace in mv3 r=robwu
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 106 Branch
See Also: → 1848346

The MDN documentation doesn't clearly express the difference between MV2 and MV3 in the level of promise support in the chrome namespace.

See bug 1848346 for an example of the resulting confusion, and https://bugzilla.mozilla.org/show_bug.cgi?id=1848346#c4 for the explanation.

This should be documented at https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Chrome_incompatibilities

Keywords: dev-doc-needed

See "promise support in Chrome clarification" #28643

See Also: → 1891186
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: