-
Notifications
You must be signed in to change notification settings - Fork 51.1k
Expand file tree
/
Copy pathdynamicallyInjectContentScripts.js
More file actions
62 lines (58 loc) · 1.94 KB
/
dynamicallyInjectContentScripts.js
File metadata and controls
62 lines (58 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* global chrome */
const contentScriptsToInject = [
{
id: '@react-devtools/proxy',
js: ['build/proxy.js'],
matches: ['<all_urls>'],
persistAcrossSessions: true,
runAt: 'document_start',
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/fallback-eval-context',
js: ['build/fallbackEvalContext.js'],
matches: ['<all_urls>'],
persistAcrossSessions: true,
runAt: 'document_start',
world: chrome.scripting.ExecutionWorld.MAIN,
},
{
id: '@react-devtools/hook',
js: ['build/installHook.js'],
matches: ['<all_urls>'],
persistAcrossSessions: true,
runAt: 'document_start',
world: chrome.scripting.ExecutionWorld.MAIN,
},
{
id: '@react-devtools/hook-settings-injector',
js: ['build/hookSettingsInjector.js'],
matches: ['<all_urls>'],
persistAcrossSessions: true,
runAt: 'document_start',
},
];
async function dynamicallyInjectContentScripts() {
try {
// Using this, instead of filtering registered scrips with `chrome.scripting.getRegisteredScripts`
// because of https://bugs.chromium.org/p/chromium/issues/detail?id=1393762
// This fixes registering proxy content script in incognito mode
await chrome.scripting.unregisterContentScripts();
// 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
// so the hook can be detected by react reconciler
await chrome.scripting.registerContentScripts(contentScriptsToInject);
} catch (error) {
console.error(error);
}
}
dynamicallyInjectContentScripts();