Add ability to set global preload scripts
This commit is contained in:
parent
d598aa1a67
commit
0ddd078aaf
10 changed files with 116 additions and 13 deletions
|
@ -67,6 +67,7 @@ electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', (ev
|
|||
let nodeIntegration = 'false'
|
||||
let webviewTag = 'false'
|
||||
let preloadScript = null
|
||||
const globalPreloadScripts = []
|
||||
let isBackgroundPage = false
|
||||
let appPath = null
|
||||
for (let arg of process.argv) {
|
||||
|
@ -86,6 +87,8 @@ for (let arg of process.argv) {
|
|||
appPath = arg.substr(arg.indexOf('=') + 1)
|
||||
} else if (arg.indexOf('--webview-tag=') === 0) {
|
||||
webviewTag = arg.substr(arg.indexOf('=') + 1)
|
||||
} else if (arg.indexOf('--global-preload') === 0) {
|
||||
globalPreloadScripts.push(arg.substr(arg.indexOf('=') + 1))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,6 +174,15 @@ if (nodeIntegration === 'true') {
|
|||
})
|
||||
}
|
||||
|
||||
for (const globalPreloadScript of globalPreloadScripts) {
|
||||
try {
|
||||
require(globalPreloadScript)
|
||||
} catch (error) {
|
||||
console.error('Unable to load global preload script: ' + globalPreloadScript)
|
||||
console.error(error.stack || error.message)
|
||||
}
|
||||
}
|
||||
|
||||
// Load the script specfied by the "preload" attribute.
|
||||
if (preloadScript) {
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue