diff --git a/lib/browser/guest-window-manager.js b/lib/browser/guest-window-manager.js index c0a5efb262..62abc8663c 100644 --- a/lib/browser/guest-window-manager.js +++ b/lib/browser/guest-window-manager.js @@ -47,6 +47,11 @@ const mergeBrowserWindowOptions = function (embedder, options) { options.webPreferences.nodeIntegration = false } + // Enable context isolation on child window if enable on parent window + if (embedder.getWebPreferences().contextIsolation === true) { + options.webPreferences.contextIsolation = true + } + // Sets correct openerId here to give correct options to 'new-window' event handler options.webPreferences.openerId = embedder.id diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index f28759ccbb..b777c684d1 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -1903,6 +1903,15 @@ describe('BrowserWindow module', function () { }) w.loadURL('file://' + fixtures + '/api/isolated.html') }) + + it('enables context isolation on child windows', function (done) { + app.once('browser-window-created', function (event, window) { + assert.equal(window.webContents.getWebPreferences().contextIsolation, true) + done() + }) + + w.loadURL('file://' + fixtures + '/pages/window-open.html') + }) }) describe('offscreen rendering', function () {