diff --git a/public/libs/views.js b/public/libs/views.js index ac37689f..e30cd26f 100644 --- a/public/libs/views.js +++ b/public/libs/views.js @@ -1,6 +1,5 @@ const { BrowserView, - BrowserWindow, app, session, shell, @@ -35,6 +34,7 @@ const addView = (browserWindow, workspace) => { const view = new BrowserView({ webPreferences: { + nativeWindowOpen: true, nodeIntegration: false, contextIsolation: true, partition: shareWorkspaceBrowsingData ? 'persist:shared' : `persist:${workspace.id}`, @@ -86,7 +86,7 @@ const addView = (browserWindow, workspace) => { // edge case to handle failed auth if (errorCode === -300 && view.webContents.getURL().length === 0) { - view.webContents.loadURL(workspace.homeUrl); + view.webContents.loadURL(getWorkspace(workspace.id).homeUrl); } }); @@ -104,8 +104,8 @@ const addView = (browserWindow, workspace) => { } }); - view.webContents.on('new-window', (e, nextUrl, frameName, disposition, options, additionalFeatures, referrer) => { - const curDomain = extractDomain(workspace.homeUrl); + view.webContents.on('new-window', (e, nextUrl, frameName, disposition, options) => { + const curDomain = extractDomain(getWorkspace(workspace.id).homeUrl); const nextDomain = extractDomain(nextUrl); // load in same window @@ -120,24 +120,21 @@ const addView = (browserWindow, workspace) => { // open new window normally if domain is not defined or same domain (about:) if (nextDomain === null || nextDomain === curDomain || nextUrl.indexOf('oauth') > -1) { - e.preventDefault(); - const popupWin = new BrowserWindow({ - width: 500, - height: 500, - webPreferences: { - nodeIntegration: false, - contextIsolation: true, - partition: shareWorkspaceBrowsingData ? 'persist:shared' : `persist:${workspace.id}`, - preload: path.join(__dirname, '..', 'preload', 'view.js'), - }, + // e.preventDefault(); + // https://gist.github.com/Gvozd/2cec0c8c510a707854e439fb15c561b0 + // options.webPreferences.affinity is not needed + Object.assign(options, { + parent: browserWindow, }); - popupWin.loadURL(nextUrl, { httpReferrer: referrer }); - e.newGuest = popupWin; + // default behavior is similar so no need for overwriting + // const popupWin = new BrowserWindow(options); + // e.newGuest = popupWin; return; } // open external url in browser if domain doesn't match. + e.preventDefault(); shell.openExternal(nextUrl); }); @@ -197,9 +194,6 @@ const addView = (browserWindow, workspace) => { view.webContents.send('update-target-url', url); }); - view.webContents.loadURL((rememberLastPageVisited && workspace.lastUrl) - || workspace.homeUrl); - views[workspace.id] = view; if (workspace.active) { @@ -222,6 +216,9 @@ const addView = (browserWindow, workspace) => { height: true, }); } + + view.webContents.loadURL((rememberLastPageVisited && workspace.lastUrl) + || workspace.homeUrl); }; const getView = (id) => views[id];