win.webContents.setWindowOpenHandler(({ url }) => {
/*
Here you will allow the browserWindow creation and configure it
look a bit of the documentation here https://www.electronjs.org/es/docs/latest/api/web-contents#contentssetwindowopenhandlerhandler
*/
}
win.webContents.on('did-create-window', (childWindow) => {
/*
Here you can use childWindow to set the new user agent for example
here documentation for did-create-window https://www.electronjs.org/es/docs/latest/api/web-contents#evento-did-create-window
*/
childwindow.webContents.setUserAgent('your-custom-user-agent)
});
1条答案
按热度按时间qij5mzcb1#
target=_black将创建一个新的browserWindow对象,因此您可以使用webContents API跟踪此事件,并将自定义userAgent应用于此新的browserWindow对象。例如:
主窗口上需要此webContents事件
此SetWindowOpenHandler事件将允许创建窗口,现在,通过事件did-create-window,您将获得新的BrowserWindow对象,并通过该引用,您将能够设置自定义userAgent
我希望这对你有帮助,再见!