mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
feat[react-devtools]: support Manifest v3 for Firefox extension (#30824)
Firefox [finally supports `ExecutionWorld.MAIN`](https://bugzilla.mozilla.org/show_bug.cgi?id=1736575) in content scripts, which means we can migrate the browser extension to Manifest V3. This PR also removes a bunch of no longer required explicit branching for Firefox case, when we are using Manifest V3-only APIs. We are also removing XMLHttpRequest injection, which is no longer needed and restricted in Manifest V3. The new standardized approach (same as in Chromium) doesn't violate CSP rules, which means that extension can finally be used for apps running in production mode.
This commit is contained in:
+34
-56
@@ -1,58 +1,39 @@
|
||||
/* global chrome */
|
||||
|
||||
// Firefox doesn't support ExecutionWorld.MAIN yet
|
||||
// equivalent logic for Firefox is in prepareInjection.js
|
||||
const contentScriptsToInject = __IS_FIREFOX__
|
||||
? [
|
||||
{
|
||||
id: '@react-devtools/proxy',
|
||||
js: ['build/proxy.js'],
|
||||
matches: ['<all_urls>'],
|
||||
persistAcrossSessions: true,
|
||||
runAt: 'document_end',
|
||||
},
|
||||
{
|
||||
id: '@react-devtools/file-fetcher',
|
||||
js: ['build/fileFetcher.js'],
|
||||
matches: ['<all_urls>'],
|
||||
persistAcrossSessions: true,
|
||||
runAt: 'document_end',
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
id: '@react-devtools/proxy',
|
||||
js: ['build/proxy.js'],
|
||||
matches: ['<all_urls>'],
|
||||
persistAcrossSessions: true,
|
||||
runAt: 'document_end',
|
||||
world: chrome.scripting.ExecutionWorld.ISOLATED,
|
||||
},
|
||||
{
|
||||
id: '@react-devtools/file-fetcher',
|
||||
js: ['build/fileFetcher.js'],
|
||||
matches: ['<all_urls>'],
|
||||
persistAcrossSessions: true,
|
||||
runAt: 'document_end',
|
||||
world: chrome.scripting.ExecutionWorld.ISOLATED,
|
||||
},
|
||||
{
|
||||
id: '@react-devtools/hook',
|
||||
js: ['build/installHook.js'],
|
||||
matches: ['<all_urls>'],
|
||||
persistAcrossSessions: true,
|
||||
runAt: 'document_start',
|
||||
world: chrome.scripting.ExecutionWorld.MAIN,
|
||||
},
|
||||
{
|
||||
id: '@react-devtools/renderer',
|
||||
js: ['build/renderer.js'],
|
||||
matches: ['<all_urls>'],
|
||||
persistAcrossSessions: true,
|
||||
runAt: 'document_start',
|
||||
world: chrome.scripting.ExecutionWorld.MAIN,
|
||||
},
|
||||
];
|
||||
const contentScriptsToInject = [
|
||||
{
|
||||
id: '@react-devtools/proxy',
|
||||
js: ['build/proxy.js'],
|
||||
matches: ['<all_urls>'],
|
||||
persistAcrossSessions: true,
|
||||
runAt: 'document_end',
|
||||
world: chrome.scripting.ExecutionWorld.ISOLATED,
|
||||
},
|
||||
{
|
||||
id: '@react-devtools/file-fetcher',
|
||||
js: ['build/fileFetcher.js'],
|
||||
matches: ['<all_urls>'],
|
||||
persistAcrossSessions: true,
|
||||
runAt: 'document_end',
|
||||
world: chrome.scripting.ExecutionWorld.ISOLATED,
|
||||
},
|
||||
{
|
||||
id: '@react-devtools/hook',
|
||||
js: ['build/installHook.js'],
|
||||
matches: ['<all_urls>'],
|
||||
persistAcrossSessions: true,
|
||||
runAt: 'document_start',
|
||||
world: chrome.scripting.ExecutionWorld.MAIN,
|
||||
},
|
||||
{
|
||||
id: '@react-devtools/renderer',
|
||||
js: ['build/renderer.js'],
|
||||
matches: ['<all_urls>'],
|
||||
persistAcrossSessions: true,
|
||||
runAt: 'document_start',
|
||||
world: chrome.scripting.ExecutionWorld.MAIN,
|
||||
},
|
||||
];
|
||||
|
||||
async function dynamicallyInjectContentScripts() {
|
||||
try {
|
||||
@@ -61,9 +42,6 @@ async function dynamicallyInjectContentScripts() {
|
||||
// This fixes registering proxy content script in incognito mode
|
||||
await chrome.scripting.unregisterContentScripts();
|
||||
|
||||
// equivalent logic for Firefox is in prepareInjection.js
|
||||
// Manifest V3 method of injecting content script
|
||||
// TODO(hoxyq): migrate Firefox to V3 manifests
|
||||
// Note: the "world" option in registerContentScripts is only available in Chrome v102+
|
||||
// It's critical since it allows us to directly run scripts on the "main" world on the page
|
||||
// "document_start" allows it to run before the page's scripts
|
||||
|
||||
Reference in New Issue
Block a user