Re: [whatwg/dom] [Proposal] Add EventTarget.getEventListeners() (#412)

> developers can already intercept addEventListener by doing something like

yes, it was mentioned, but on the other side, developers can secure nothing will ever interfere with their intent if your code runs earlier (see polyfills)

```js
const {bind: b, call: c} = Function;
const {addEventListener} = EventTarget.prototype;
const addListener = b.call(c, addEventListener);

// any time later on ...
addListener(document.body, 'click', () => { console.log('safe'); });
```

We do this already in explicit circumstances to avoid evil scripts intercepting, removing, or mutating our listeners behaviors, but extensions can guarantee (in some browser) their code executes before anything else.

Again, I think this feature would be a good one for Web Extensions, at least to pave the path, but I also think user land can have a centralized library authors can use to retrieve all listeners, if added/remove through such centralized reference.

That would be also fine, like:

```js
EventTarget.addPublicEventListener(element, listener, options);
```

Now, that would be cool ... changing a very long time expected behavior where many based their libraries around looks like an unnecessary, imho undesired, breaking change I hope won't land as amend of the current methods.

I would be more than OK making it land as new method, but I guess that will also fall into the "*opt-in*" is less effective than "*opt-out*", but then again, if this lands as default behavior, we need to be sure we patch that default behavior and exclude any of our listeners to be exposed in the wild to undesired evil scripts.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/412#issuecomment-1063045000
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/412/1063045000@github.com>

Received on Wednesday, 9 March 2022 15:32:42 UTC