Skip to content

Commit 2149d1e

Browse files
committed
detect electron main and renderer process
1 parent 82a4b79 commit 2149d1e

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

src/lib/is-browser.ts

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
const isStandardBrowserEnv = () => {
22
// window is only defined when it is a browser
33
if (typeof window !== 'undefined') {
4-
// Is the process an electron application
5-
// check if we are in electron `renderer`
6-
const electronRenderCheck =
7-
typeof navigator !== 'undefined' &&
8-
navigator.userAgent?.toLowerCase().indexOf(' electron/') > -1
9-
if (electronRenderCheck && process?.versions) {
10-
const electronMainCheck = Object.prototype.hasOwnProperty.call(
11-
process.versions,
12-
'electron',
13-
)
14-
// Both electron checks are only true if the following webPreferences are set in the main electron BrowserWindow()
15-
// webPreferences: {
16-
// sandbox: false,
17-
// nodeIntegration: true
18-
// contextIsolation: false
19-
// }
20-
return !electronMainCheck
4+
if (typeof process !== 'undefined') {
5+
if (process.type === 'renderer') return true
6+
else if (typeof process.electron !== 'undefined') return false
217
}
8+
229
return typeof window.document !== 'undefined'
2310
}
11+
2412
// return false if nothing is detected
2513
return false
2614
}

0 commit comments

Comments
 (0)