Open Bug 1896267 Opened 1 year ago Updated 1 year ago

extends EventTarget does not work in MV3 content script

Categories

(WebExtensions :: General, defect, P3)

Firefox 125
defect

Tracking

(firefox126 affected, firefox127 affected)

REOPENED
Tracking Status
firefox126 --- affected
firefox127 --- affected

People

(Reporter: descent-tact0m, Unassigned)

References

(Depends on 1 open bug)

Details

Attachments

(2 files)

Attached file bug.zip

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:125.0) Gecko/20100101 Firefox/125.0

Steps to reproduce:

  1. Download bug.zip
  2. Open about:debugging#/runtime/this-firefox
  3. Install the extension
  4. Open https://example.com/
  5. Click the "reproduce" extension

Actual results:

t.f should be 1, actually be undefined

Expected results:

t.f should be 1, actually be 1

The Bugbug bot thinks this bug should belong to the 'WebExtensions::Untriaged' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Product: Firefox → WebExtensions

Hello,

I reproduced the issue on the latest Nightly (127.0a1/20240512212637), Beta (126.0/20240509170740) and Release (125.0.3/20240425211020) under Windows 10 and Ubuntu 22.04 LTS.

Once the “reproduce” extension is clicked, a pop-up is displayed, stating “t.f should be 1, actually be undefined”, confirming the issue. See the attached screenshot for more details.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Status: NEW → RESOLVED
Closed: 1 year ago
Duplicate of bug: 1820521
Resolution: --- → DUPLICATE

Re-opening because there is something special going on.
Still marking as dependency of bug 1820521 because I anticipate that fixing that bug will resolve this bug, and we should add a unit test to ensure that this bug remains fixed.

What is going on here is that EventTarget in MV2 is an EventTarget instance associated with the content script sandbox (window.EventTarget === EventTarget is false). This is because in MV2, the content script sandbox has its own WebSocket class definition, and because WebSocket inherits from EventTarget, the EventTarget symbol is also imported in the content script sandbox.

In MV3, the special WebSocket import is no longer done (implemented in bug 1578405), which also results in EventTarget being the Xray-wrapped version of the constructor shared with the web page, which is affected by bug 1820521.

Bug 1820521 is not visible in MV2 because the implementation coincidentally offers a work-around that hides this specific bug (i.e. the content script-specific EventTarget). We do still not want to copy that behavior to MV3 because mixing of prototypes/constructors is a recipe for confusion and inconsistencies, as seen in bug 1763240 and explained at https://bugzilla.mozilla.org/show_bug.cgi?id=1763240#c16

Status: RESOLVED → REOPENED
Component: Untriaged → General
Depends on: 1820521
No longer duplicate of bug: 1820521
Resolution: DUPLICATE → ---
See Also: → 1578405, 1763240
See Also: → 1894258
Severity: -- → S3
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: