Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b8dc0cf

Browse files
Add devtron via preload script (sindresorhus#82)
Co-authored-by: Sindre Sorhus <[email protected]>
1 parent 3f92ef4 commit b8dc0cf

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ declare const electronDebug: {
6868
@param window - Default: `BrowserWindow.getFocusedWindow()`
6969
*/
7070
openDevTools(window?: BrowserWindow): void;
71+
72+
/**
73+
The absolute path to a preload script to use in [`session#setPreloads()`](https://www.electronjs.org/docs/api/session#sessetpreloadspreloads).
74+
75+
Use it to enable `devtron` even when [`nodeIntegration`](https://www.electronjs.org/docs/api/browser-window#new-browserwindowoptions) is turned off.
76+
*/
77+
preloadScriptPath: string;
7178
};
7279

7380
export = electronDebug;

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const {app, BrowserWindow, session} = require('electron');
3+
const path = require('path');
34
const localShortcut = require('electron-localshortcut');
45
const isDev = require('electron-is-dev');
56

@@ -120,3 +121,4 @@ module.exports = options => {
120121
module.exports.refresh = refresh;
121122
module.exports.devTools = devTools;
122123
module.exports.openDevTools = openDevTools;
124+
module.exports.preloadScriptPath = path.join(__dirname, 'preload.js');

preload.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
window.__devtron = {require, process};

readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Open DevTools and focus the Element Inspector tool.
3333
Just install any of these extension and they'll be activated for you:
3434

3535
- [devtron](https://electronjs.org/devtron) - The official Electron DevTools extension
36+
- You need to use [`preloadScriptPath`](#preloadScriptPath) if the `BrowserWindow`'s `nodeIntegration` is off.
3637
- [electron-react-devtools](https://github.com/firejune/electron-react-devtools) - React DevTools extension for Electron
3738

3839
## Install
@@ -116,6 +117,14 @@ Open DevTools for the specified `BrowserWindow` instance or the focused one.
116117
Type: `BrowserWindow`\
117118
Default: The focused `BrowserWindow`
118119

120+
### preloadScriptPath
121+
122+
Type: `string`
123+
124+
The absolute path to a preload script to use in [`session#setPreloads()`](https://www.electronjs.org/docs/api/session#sessetpreloadspreloads).
125+
126+
Use it to enable `devtron` even when [`nodeIntegration`](https://www.electronjs.org/docs/api/browser-window#new-browserwindowoptions) is turned off.
127+
119128
## Related
120129

121130
- [electron-util](https://github.com/sindresorhus/electron-util) - Useful utilities for developing Electron apps and modules

0 commit comments

Comments
 (0)