Closed Bug 1372649 Opened 7 years ago Closed 7 years ago
Component: Untriaged → WebExtensions: General
Product: Firefox → Toolkit
I took a look at this and it seems to be another of the content scripts "chrome incompatibilities" that are going to be fixed by Bug 1208775 ("this !== window within content_scripts"). The issue can be easily reproduce by running the attached extension, and it can also be reproduced with the following minimal content script: ``` const testUnbindedAddEventListener = window.addEventListener; testUnbindedAddEventListener("click", (...args) => console.log("CS Click listener", args)); ``` The fix suggested in the content script that the attached backbone.zip test extension contains seems to be the best one available until Bug 1208775 has been fixed: ``` window.addEventListener = window.addEventListener.bind(window); ... // similar redefinition for any other of the window DOM methods that are going to be used "unbinded" ``` The reason why the above workaround fixes the issue is simple: - when we unbind `addEventListener`: - in a webpage, `window` is what will be used as the "fallback" for `this` in the "unbinded" method call - in a WebExtensions Content Script, the content script sandbox is what will be used as the "fallback" for `this` in the "unbinded" method call By redefining that methods and explicitly binding `this` to the `window` reference, we are manually workarounding the issue that Bug 1208775 should fix for this and other issues related to this behavior.
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.