Skip to content

Instantly share code, notes, and snippets.

@KochiyaOcean
Last active October 28, 2021 15:03
Show Gist options
  • Save KochiyaOcean/72a8040c33a7deeebdfe88d409d8ca0b to your computer and use it in GitHub Desktop.
Save KochiyaOcean/72a8040c33a7deeebdfe88d409d8ca0b to your computer and use it in GitHub Desktop.
Example of Webview ContextIsolation Issue
<!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>
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
})
});
{
"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"
}
}
// 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 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment