Open
Bug 1473306
Opened 7 years ago
Updated 9 months ago
EventTarget does not work as expected in content scripts of addons
Categories
(WebExtensions :: General, defect, P3)
WebExtensions
General
Tracking
(firefox61 affected, firefox62 affected, firefox63 affected)
NEW
People
(Reporter: uhyohyo, Assigned: robwu)
References
(Depends on 1 open bug)
Details
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
Steps to reproduce:
1. download and install an example addon from: https://gist.github.com/uhyo/895e91d2b7a4434a8690145f53ee8277
2. open whatever page you like and inspect the console output
Actual results:
Following two lines are printed by the addon:
```
Test 1: raw EventTarget
Test 2: subclass of EventTarget
```
Expected results:
Following four lines should be printed.
```
Test 1: raw EventTarget
foo event emitted: 123
Test 2: subclass of EventTarget
foo event emitted: 456
```
The problem is that the listeners added to the EventTargets are not fired by dispatchEvent().
It seems to happen only in a content script; indeed, the above four lines are printed
when the same script is run directly on a page.
Comment 1•7 years ago
|
||
I reproduced the issue on Firefox 61.0.1, Firefox 62.0b6 and Nightly 63.0a1 (2018-07-09) [Ubuntu 16.04].
Status: UNCONFIRMED → NEW
status-firefox61:
--- → affected
status-firefox62:
--- → affected
status-firefox63:
--- → affected
Component: Untriaged → Debugger
Ever confirmed: true
Product: Firefox → DevTools
Version: 63 Branch → Trunk
Updated•6 years ago
|
Component: Debugger → DOM: Events
Product: DevTools → Core
Updated•6 years ago
|
Component: DOM: Events → General
Product: Core → WebExtensions
Updated•6 years ago
|
Flags: needinfo?(rob)
Priority: -- → P3
Assignee | ||
Comment 2•6 years ago
|
||
This is a flaw in the global method proxy wrapper at [1].
A work-around for extension code is to use window.EventTarget instead of the EventTarget global, like this:
var e = new window.EventTarget();
e.addEventListener('foo', (e) => console.log('foo event emitted'));
e.dispatchEvent(new CustomEvent('foo'));
Assigning to myself because I intend to resume work on Sandbox globals at some point (bug 1468579 to start with).
Assignee: nobody → rob
Flags: needinfo?(rob)
I would like to extend the bug report a bit.
window.EventTarget
unfortunately does not support inheritance, so the window.EventTarget
is not working for every case.
Updated•2 years ago
|
Severity: normal → S3
Assignee | ||
Comment 5•9 months ago
|
||
Case 2 of this report depends on bug 1820521.
Case 1 was also shown at bug 1894258, and might or might not be fixed with the same fix.
Depends on: 1820521
You need to log in
before you can comment on or make changes to this bug.
Description
•