Skip to content

Commit

Permalink
refactor: update setWindowOpenHandler in app.ts to handle additional …
Browse files Browse the repository at this point in the history
…features
  • Loading branch information
purocean committed Oct 9, 2024
1 parent e5e9559 commit c45e991
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ if (!gotTheLock) {
})
})

webContents.setWindowOpenHandler(({ url }) => {
webContents.setWindowOpenHandler(({ url, features }) => {
if (url.includes('__allow-open-window__')) {
return { action: 'allow' }
}
Expand All @@ -652,7 +652,30 @@ if (!gotTheLock) {
return { action: 'deny' }
}

return { action: 'allow' }
const webPreferences: Record<string, boolean | string> = {}

// electron not auto parse features below. https://www.electronjs.org/docs/latest/api/window-open
const extraFeatureKeys = [
'experimentalFeatures',
'nodeIntegrationInSubFrames',
'webSecurity',
]

extraFeatureKeys.forEach(key => {
const match = features.match(new RegExp(`${key}=([^,]+)`))
if (match) {
webPreferences[key] = match[1] === 'true' ? true : match[1] === 'false' ? false : match[1]
}
})

debugger

return {
action: 'allow',
overrideBrowserWindowOptions: {
webPreferences: Object.keys(webPreferences).length > 0 ? webPreferences : undefined,
}
}
})
})
}

0 comments on commit c45e991

Please sign in to comment.