-
-
Notifications
You must be signed in to change notification settings - Fork 811
/
Copy pathdevtools.js
68 lines (64 loc) · 2.14 KB
/
devtools.js
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
63
64
65
66
67
68
export const getCatchConsoleLogScript = (port) => `
window.__RN_PACKAGER_MATCHER__ = /^http:\\/\\/[^:]+:${port}/;
if (!window.__INJECT_OPEN_IN_EDITOR_SCRIPT__) {
const rndHelperQuery = 'iframe[data-devtools-extension="RNDebugger devtools helper"]';
document.addEventListener('click', event => {
if (!window.__IS_OPEN_IN_EDITOR_ENABLED__) {
return;
}
const { target } = event;
if (target.className === 'devtools-link') {
const source = target.title;
if (source && source.match(window.__RN_PACKAGER_MATCHER__)) {
const rndHelper = document.querySelector(rndHelperQuery);
if (rndHelper && rndHelper.contentWindow) {
rndHelper.contentWindow.postMessage(
{
type: 'open-in-editor',
source: source.replace(window.__RN_PACKAGER_MATCHER__, '')
},
'*'
);
return event.stopPropagation();
}
}
}
}, true);
window.__INJECT_OPEN_IN_EDITOR_SCRIPT__ = true;
}
`
export const catchConsoleLogLink = (win, host = 'localhost', port = 8081) => {
if (win.devToolsWebContents) {
return win.devToolsWebContents.executeJavaScript(`(() => {
${getCatchConsoleLogScript(host, port)}
})()`)
}
}
export const removeUnecessaryTabs = (win) => {
if (
process.env.NODE_ENV === 'production'
&& !process.env.DEBUG_RNDEBUGGER
&& win.devToolsWebContents
) {
return win.devToolsWebContents.executeJavaScript(`(() => {
const tabbedPane = UI.inspectorView.tabbedPane;
if (tabbedPane) {
tabbedPane.closeTab('elements');
tabbedPane.closeTab('security');
tabbedPane.closeTab('audits');
tabbedPane.closeTab('audits2');
tabbedPane.closeTab('lighthouse');
tabbedPane.leftToolbar().element.remove();
}
})()`)
}
}
export const activeTabs = (win) => {
if (win.devToolsWebContents) {
// Active network tab so we can do clearNetworkLogs
return win.devToolsWebContents.executeJavaScript(`(() => {
DevToolsAPI.showPanel('network');
DevToolsAPI.showPanel('console');
})()`)
}
}