Last active
October 28, 2021 15:03
-
-
Save KochiyaOcean/72a8040c33a7deeebdfe88d409d8ca0b to your computer and use it in GitHub Desktop.
Example of Webview ContextIsolation Issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
</head> | |
<body style="height: 100vh; margin: 0;"> | |
<webview src="https://github.com" style="height: 600px; width: 800px;"></webview> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var BrowserWindow = require('electron').BrowserWindow; | |
var app = require('electron').app; | |
app.commandLine.appendSwitch('disable-site-isolation-trials', true) | |
app.on('ready', function() { | |
var mainWindow; | |
mainWindow = new BrowserWindow({ | |
webPreferences: { | |
webviewTag: true, | |
nativeWindowOpen: true, | |
contextIsolation: false, | |
}, | |
}); | |
mainWindow.loadURL("file://"+ __dirname + "/index.html"); | |
mainWindow.openDevTools({detach: true}); | |
mainWindow.webContents.addListener('new-window', (e, url, frameName, disposition, options, additionalFeatures) => { | |
e.preventDefault() | |
options = { | |
...options, | |
minWidth: 200, | |
minHeight: 200, | |
webPreferences: { | |
webviewTag: true, | |
}, | |
} | |
const win = new BrowserWindow(options) | |
e.newGuest = win | |
}) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "eatable-minister-reason-6ywhd", | |
"productName": "eatable-minister-reason-6ywhd", | |
"description": "My Electron application description", | |
"keywords": [], | |
"main": "./main.js", | |
"version": "1.0.0", | |
"author": "kochiyaocean", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"dependencies": {}, | |
"devDependencies": { | |
"electron": "15.3.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// All of the Node.js APIs are available in the preload process. | |
// It has the same sandbox as a Chrome extension. | |
window.addEventListener('DOMContentLoaded', () => { | |
const replaceText = (selector, text) => { | |
const element = document.getElementById(selector) | |
if (element) element.innerText = text | |
} | |
for (const type of ['chrome', 'node', 'electron']) { | |
replaceText(`${type}-version`, process.versions[type]) | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This file is required by the index.html file and will | |
// be executed in the renderer process for that window. | |
// No Node.js APIs are available in this process because | |
// `nodeIntegration` is turned off. Use `preload.js` to | |
// selectively enable features needed in the rendering | |
// process. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Empty */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment