-
Notifications
You must be signed in to change notification settings - Fork 51k
Expand file tree
/
Copy pathhookSettingsInjector.js
More file actions
59 lines (52 loc) · 2.06 KB
/
hookSettingsInjector.js
File metadata and controls
59 lines (52 loc) · 2.06 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
/* global chrome */
/** @flow */
// We can't use chrome.storage domain from scripts which are injected in ExecutionWorld.MAIN
// This is the only purpose of this script - to send persisted settings to installHook.js content script
import type {UnknownMessageEvent} from './messages';
import type {DevToolsHookSettings} from 'react-devtools-shared/src/backend/types';
import {postMessage} from './messages';
async function messageListener(event: UnknownMessageEvent) {
if (event.source !== window) {
return;
}
if (event.data.source === 'react-devtools-hook-installer') {
if (event.data.payload.handshake) {
const settings: Partial<DevToolsHookSettings> =
await chrome.storage.local.get();
// If storage was empty (first installation), define default settings
const hookSettings: DevToolsHookSettings = {
appendComponentStack:
typeof settings.appendComponentStack === 'boolean'
? settings.appendComponentStack
: true,
breakOnConsoleErrors:
typeof settings.breakOnConsoleErrors === 'boolean'
? settings.breakOnConsoleErrors
: false,
showInlineWarningsAndErrors:
typeof settings.showInlineWarningsAndErrors === 'boolean'
? settings.showInlineWarningsAndErrors
: true,
hideConsoleLogsInStrictMode:
typeof settings.hideConsoleLogsInStrictMode === 'boolean'
? settings.hideConsoleLogsInStrictMode
: false,
disableSecondConsoleLogDimmingInStrictMode:
typeof settings.disableSecondConsoleLogDimmingInStrictMode ===
'boolean'
? settings.disableSecondConsoleLogDimmingInStrictMode
: false,
};
postMessage({
source: 'react-devtools-hook-settings-injector',
payload: {settings: hookSettings},
});
window.removeEventListener('message', messageListener);
}
}
}
window.addEventListener('message', messageListener);
postMessage({
source: 'react-devtools-hook-settings-injector',
payload: {handshake: true},
});