aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/preload-safe-debug.ts19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/preload-safe-debug.ts b/src/preload-safe-debug.ts
index d96ea9017..1136e93c1 100644
--- a/src/preload-safe-debug.ts
+++ b/src/preload-safe-debug.ts
@@ -1,8 +1,3 @@
1/*
2 eslint-disable global-require --
3 This file contains a workaround for situations were global require is problematic.
4*/
5
6/** 1/**
7 * Make sure we don't try to load `debug` in the preload script. 2 * Make sure we don't try to load `debug` in the preload script.
8 * 3 *
@@ -10,13 +5,13 @@
10 * because `debug` will try to access `localStorage` to save the log level: 5 * because `debug` will try to access `localStorage` to save the log level:
11 * https://www.npmjs.com/package/debug#user-content-browser-support 6 * https://www.npmjs.com/package/debug#user-content-browser-support
12 * 7 *
13 * We check for the presence of `ipcRenderer`, a render-only electron API, 8 * We disable the `debug` package in context isolated renderers,
14 * to detect whether we're in the renderer process. 9 * because they correspond to preload scripts.
15 * We serve the user interface from the `file://` origin, so any different origin
16 * must be a preload script.
17 */ 10 */
18module.exports = function debug(namespace: string): (...params: any[]) => void { 11module.exports = function debug(namespace: string): (...params: any[]) => void {
19 if ('ipcRenderer' in require('electron') && window.origin !== 'file://') { 12 if (typeof process === 'object' &&
13 'contextIsolated' in process &&
14 (process as unknown as { contextIsolated: string }).contextIsolated) {
20 // Only output debug messages to the console if debugging is requested. 15 // Only output debug messages to the console if debugging is requested.
21 // We don't reimplement the matching algorithm from `debug` and just dump all 16 // We don't reimplement the matching algorithm from `debug` and just dump all
22 // messages to the console if some form of `Ferdium` debugging is enabled. 17 // messages to the console if some form of `Ferdium` debugging is enabled.
@@ -25,5 +20,9 @@ module.exports = function debug(namespace: string): (...params: any[]) => void {
25 } 20 }
26 return () => { }; 21 return () => { };
27 } 22 }
23 /*
24 eslint-disable-next-line global-require --
25 This file contains a workaround for situations were global require is problematic.
26 */
28 return require('debug')(namespace); 27 return require('debug')(namespace);
29} 28}