-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix[devtools/extension]: added a workaround for proxy content script injection in firefox #27375
fix[devtools/extension]: added a workaround for proxy content script injection in firefox #27375
Conversation
Discord blocks script injection via XMLHttpRequest, which we do here. We do this only for Firefox, because it doesn't support ExecutionWorld.MAIN yet. The only other option for us is to use This is also the reason why we haven't migrated Firefox extension to manifests v3 yet. |
d16301e
to
5a6feba
Compare
@@ -2,23 +2,17 @@ | |||
|
|||
'use strict'; | |||
|
|||
window.addEventListener('unload', function ({target}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this going to break the bf-cache for pages even when the devtools is not open? https://developer.mozilla.org/en-US/docs/Web/API/Window/unload_event#usage_notes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but only this content script won't be put in bfcache
. This is our goal, because if content scripts in Firefox are not unloaded / loaded properly again, extension might not receive some important events that are necessary to start
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that it's just the script not ending up in bf-cache?
To combat this, some browsers (such as Firefox) will not place pages in the bfcache if they have unload listeners, and this is bad for performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I interpret
will not place pages in the bfcache if they have unload listeners, and this is bad for performance.
as "if page has unload listeners, it won't be in bfcache", this doesn't mean that every page won't be in bfcache.
Content scripts are loaded separately from "page", and I think for Firefox it has a distinct page, so it won't be cached, but page, which runs react application, will. I will double-check this though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm once you double check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Screen.Recording.2023-09-20.at.14.42.57.mov
Looks like it really breaks bfcache for Firefox. I've moved to pagehide / pageshow events, they are bfcache-compatible. Thanks again, re-requesting review.
…injection in firefox
5a6feba
to
45142d6
Compare
Merging this, since we've discussed it in person, cc @gsathya |
* refactor[devtools/extension]: refactored messaging logic across different parts of the extension ([hoxyq](https://github.com/hoxyq) in [#27417](#27417)) * fix[devtools/extension]: added a workaround for proxy content script injection in firefox ([hoxyq](https://github.com/hoxyq) in [#27375](#27375)) * fix[devtools/useTransition]: don't check for dispatch property when determining if hook is stateful ([hoxyq](https://github.com/hoxyq) in [#27365](#27365)) * feat[devtools/extension]: show disclaimer when page doesnt run react and refactor react polling logic ([hoxyq](https://github.com/hoxyq) in [#27373](#27373)) * feat:-Added a delete all filters action and added title to the add filter a… ([Biki-das](https://github.com/Biki-das) in [#27332](#27332)) * fix[devtools/extension]: unregister dynamically injected content scripts instead of filtering ([hoxyq](https://github.com/hoxyq) in [#27369](#27369)) * refactor[devtools/extension]: more stable element updates polling to avoid timed out errors ([hoxyq](https://github.com/hoxyq) in [#27357](#27357)) * feat[devtools/extension]: add dark theme for popup ([rakleed](https://github.com/rakleed) in [#27330](#27330))
### React upstream changes - facebook/react#27417 - facebook/react#27408 - facebook/react#27409 - facebook/react#27405 - facebook/react#27375 - facebook/react#27407 - facebook/react#27365 - facebook/react#27399 - facebook/react#27395 - facebook/react#27394 - facebook/react#27397 - facebook/react#26992 - facebook/react#27388 - facebook/react#27373 - facebook/react#27332
…injection in firefox (facebook#27375) Changes: 1. [Firefox-only] For some reason, Firefox might try to inject dynamically registered content script in pages like `about:blank`. I couldn't find a way to change this behaviour, `about:` is not a valid scheme, so we can't exclude it and `match_about_blank` flag is not supported in `chrome.scripting.registerContentScripts`. 2. While navigating the history in Firefox, some content scripts might not be re-injected and still be alive. To handle this, we are now patching `window` with `__REACT_DEVTOOLS_PROXY_INJECTED__` flag, to make sure that proxy is injected and only once. This flag is cleared on `pagehide` event.
* refactor[devtools/extension]: refactored messaging logic across different parts of the extension ([hoxyq](https://github.com/hoxyq) in [facebook#27417](facebook#27417)) * fix[devtools/extension]: added a workaround for proxy content script injection in firefox ([hoxyq](https://github.com/hoxyq) in [facebook#27375](facebook#27375)) * fix[devtools/useTransition]: don't check for dispatch property when determining if hook is stateful ([hoxyq](https://github.com/hoxyq) in [facebook#27365](facebook#27365)) * feat[devtools/extension]: show disclaimer when page doesnt run react and refactor react polling logic ([hoxyq](https://github.com/hoxyq) in [facebook#27373](facebook#27373)) * feat:-Added a delete all filters action and added title to the add filter a… ([Biki-das](https://github.com/Biki-das) in [facebook#27332](facebook#27332)) * fix[devtools/extension]: unregister dynamically injected content scripts instead of filtering ([hoxyq](https://github.com/hoxyq) in [facebook#27369](facebook#27369)) * refactor[devtools/extension]: more stable element updates polling to avoid timed out errors ([hoxyq](https://github.com/hoxyq) in [facebook#27357](facebook#27357)) * feat[devtools/extension]: add dark theme for popup ([rakleed](https://github.com/rakleed) in [facebook#27330](facebook#27330))
…injection in firefox (#27375) Changes: 1. [Firefox-only] For some reason, Firefox might try to inject dynamically registered content script in pages like `about:blank`. I couldn't find a way to change this behaviour, `about:` is not a valid scheme, so we can't exclude it and `match_about_blank` flag is not supported in `chrome.scripting.registerContentScripts`. 2. While navigating the history in Firefox, some content scripts might not be re-injected and still be alive. To handle this, we are now patching `window` with `__REACT_DEVTOOLS_PROXY_INJECTED__` flag, to make sure that proxy is injected and only once. This flag is cleared on `pagehide` event. DiffTrain build for commit f9d75e3.
Changes:
about:blank
. I couldn't find a way to change this behaviour,about:
is not a valid scheme, so we can't exclude it andmatch_about_blank
flag is not supported inchrome.scripting.registerContentScripts
.window
with__REACT_DEVTOOLS_PROXY_INJECTED__
flag, to make sure that proxy is injected and only once. This flag is cleared onpagehide
event.