})
})
+ describe('isolated option', () => {
+ it('separates the page context from the Electron/preload context', (done) => {
+ if (w != null) w.destroy()
+
+ ipcMain.once('isolated-world', (event, data) => {
+ assert.deepEqual(data, {
+ preloadContext: {
+ preloadProperty: 'number',
+ pageProperty: 'undefined',
+ typeofRequire: 'function',
+ typeofProcess: 'object'
+ },
+ pageContext: {
+ preloadProperty: 'undefined',
+ pageProperty: 'string',
+ typeofRequire: 'undefined',
+ typeofProcess: 'undefined'
+ }
+ })
+ done()
+ })
+
+ w = new BrowserWindow({
+ show: false,
+ webPreferences: {
+ isolated: true,
+ preload: path.join(fixtures, 'api', 'isolated-preload.js')
+ }
+ })
+ w.loadURL('file://' + fixtures + '/api/isolated.html')
+ })
+ })
+
describe('offscreen rendering', function () {
beforeEach(function () {
if (w != null) w.destroy()
--- /dev/null
+const {ipcRenderer} = require('electron')
+
+window.foo = 3
+
+window.addEventListener('message', (event) => {
+ ipcRenderer.send('isolated-world', {
+ preloadContext: {
+ preloadProperty: typeof window.foo,
+ pageProperty: typeof window.hello,
+ typeofRequire: typeof require,
+ typeofProcess: typeof process
+ },
+ pageContext: event.data
+ })
+})
--- /dev/null
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Isolated World</title>
+ <script>
+ window.hello = 'world'
+ window.postMessage({
+ preloadProperty: typeof window.foo,
+ pageProperty: typeof window.hello,
+ typeofRequire: typeof require,
+ typeofProcess: typeof process
+ }, '*')
+ </script>
+ </head>
+ <body>
+
+ </body>
+</html>