Skip to content

Commit

Permalink
add open handler
Browse files Browse the repository at this point in the history
  • Loading branch information
fabyday committed Jul 2, 2024
1 parent 8c0e88c commit fae2436
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions typescript_src/component/mainview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,36 @@ export const get_instance = (conf : Configure):BrowserWindow =>{
// mainView.webContents.openDevTools({mode : "right"})
// mainView.loadURL(process.env.IS_DEV? "http://localhost:3000/main.html" : html_path)
// console.log(extensions.getContextMenuItems(mainView.webContents))

app.on('web-contents-created', async (event, webContents)=>{
const type = webContents.getType()
const url = webContents.getURL()

console.log(`'web-contents-created' event [type:${type}, url:${url}]`)

webContents.setWindowOpenHandler((details) => {
switch (details.disposition) {
case 'foreground-tab':
case 'background-tab':
case 'new-window': {
// setWindowOpenHandler doesn't yet support creating BrowserViews
// instead of BrowserWindows. For now, we're opting to break
// window.open until a fix is available.
// https://github.com/electron/electron/issues/33383
queueMicrotask(() => {
mainView?.loadURL(details.url)
console.log("dis ", details.disposition, "url", url)
})

return { action: 'deny' }
}
default:
return { action: 'allow' }
}

})
})


// console.log(table)
// e.preventDefault();
Expand Down

0 comments on commit fae2436

Please sign in to comment.