Skip to content

Commit 43abc4f

Browse files
committed
Permission denied to access property eventPhase
> There was an attempt to access an object for which you have no permission. —https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Property_access_denied This is a frequent exception from Firefox browsers with extensions that inject third-party scripts. The script dispatches an event that bubbles up to the document listener which tries to access its eventPhase property. This is not allowed because the event was generated from a third-party origin. So attempt to read the property from the event, while catching errors, to determine if we're allowed to use it. This seems like something the browser should shield from the first-party site but here we are.
1 parent ac2d787 commit 43abc4f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

delegated-events.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,19 @@ function defineCurrentTarget(event, getter) {
6262
});
6363
}
6464

65+
function canDispatch(event) {
66+
try {
67+
event.eventPhase;
68+
return true;
69+
} catch (_) {
70+
return false;
71+
}
72+
}
73+
6574
function dispatch(event) {
66-
const events = event.eventPhase === 1 ? captureEvents : bubbleEvents;
75+
if (!canDispatch(event)) return;
6776

77+
const events = event.eventPhase === 1 ? captureEvents : bubbleEvents;
6878
const selectors = events[event.type];
6979
if (!selectors) return;
7080

0 commit comments

Comments
 (0)