-
Notifications
You must be signed in to change notification settings - Fork 47.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DevTools] upgrade to Manifest V3 (#25145)
## Summary resolves #24522 To upgrade to Manifest V3, one of the biggest issue is that we are no longer allowed to add a script element with code in textContent so that it would run synchronously. It's necessary for us because we need to inject a global hook for react reconciler to detect whether devtools exist. To do that, we'll leverage a new API `chrome.scripting.registerContentScripts` in V3. Particularly, we rely on the "world" option (added in Chrome v102 [commit](https://chromium.googlesource.com/chromium/src/+/e5ad3451c17b21341b0b9019b074801c44c92c9f)) to run it in the "main world" on the page. This PR also renames a few content script files so that it's easier to tell them apart from other extension scripts and understand the purpose of each of them. Manifest V3 is not yet ready for Firefox, so we need to keep some code for compatibility. ## How did you test this change? `yarn build:chrome && yarn test:chrome` `yarn build:edge && yarn test:edge` `yarn build:firefox && yarn test:firefox`
- Loading branch information
1 parent
973b90b
commit 6dbccb9
Showing
14 changed files
with
268 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/react-devtools-extensions/src/contentScripts/installHook.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {installHook} from 'react-devtools-shared/src/hook'; | ||
|
||
// avoid double execution | ||
if (!window.hasOwnProperty('__REACT_DEVTOOLS_GLOBAL_HOOK__')) { | ||
installHook(window); | ||
|
||
// detect react | ||
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.on('renderer', function({ | ||
reactBuildType, | ||
}) { | ||
window.postMessage( | ||
{ | ||
source: 'react-devtools-detector', | ||
reactBuildType, | ||
}, | ||
'*', | ||
); | ||
}); | ||
|
||
// save native values | ||
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.nativeObjectCreate = Object.create; | ||
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.nativeMap = Map; | ||
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.nativeWeakMap = WeakMap; | ||
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.nativeSet = Set; | ||
} |
Oops, something went wrong.