Created
January 7, 2019 17:44
-
-
Save vviikk/d209b5d336c3b59c6fcd674982a91c00 to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
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
<html> | |
<head> | |
<style> | |
webview { | |
display: inline-flex; | |
width: 800px; | |
height: 600px; | |
} | |
</style> | |
</head> | |
<body> | |
<form name="form"> | |
<input name="input" placeholder="https://messenger.com/" value="https://messenger.com"> | |
<button type="submit">submit</button> | |
</form> | |
<div class="tabs"> | |
</div> | |
<div class="webviews"> | |
</div> | |
<!--<webview src="https://messenger.com/" autosize="on" nodeintegration="on" disablewebsecurity="on" webpreferences="allowRunningInsecureContent"></webview>--> | |
<script type="text/javascript"> | |
require('./renderer.js') | |
</script> | |
</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
const {app, BrowserWindow, BrowserView} = require('electron') | |
app.on('ready', createWindow) | |
function createWindow(){ | |
let win = new BrowserWindow({ | |
width: 1000, | |
height: 600, | |
height: 600, | |
"node-integration": "iframe", // and this line | |
"web-preferences": { | |
"web-security": false, | |
"nodeIntegration": false, | |
} | |
}) | |
win.on('closed', () => { | |
win = null | |
}) | |
// In the main process. | |
const { BrowserView } = require('electron') | |
const tabs = [ | |
{ | |
url: 'https://google.com' | |
}, | |
{ | |
url: 'https://web.whatsapp.com' | |
}, | |
{ | |
url: 'https://messenger.com' | |
} | |
] | |
// let win = new BrowserWindow({ width: 800, height: 600 }) | |
// win.on('closed', () => { | |
// win = null | |
// }) | |
const createView = (url, title = '', setAsMain = false) => { | |
const view = new BrowserView({ | |
webPreferences: { | |
nodeIntegration: false | |
} | |
}) | |
if (setAsMain) win.setBrowserView(view) | |
view.setBounds({ x: 0, y: 50, width: 1000, height: 550 }) | |
view.webContents.loadURL(url) | |
} | |
const views = tabs.map(({url}) => createView(url)) | |
win.webContents.openDevTools() | |
// Load a remote URL | |
//win.loadURL('https://github.com') | |
// Or load a local HTML file | |
win.loadURL(`file://${__dirname}/index.html`) | |
/*win.webContents.session.webRequest.onHeadersReceived({}, (d, c) => { | |
if(d.responseHeaders['x-frame-options'] || d.responseHeaders['X-Frame-Options']){ | |
delete d.responseHeaders['x-frame-options'] | |
delete d.responseHeaders['X-Frame-Options'] | |
} | |
c({cancel: false, responseHeaders: d.responseHeaders}) | |
})*/ | |
} | |
//app.commandLine.appendSwitch('disable-web-security') |
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
const {app, BrowserWindow, BrowserView} = require('electron').remote | |
let tabs = document.querySelector(".tabs") | |
let webviews = document.querySelector(".webviews") | |
document.getElementsByTagName("form")[0].onsubmit = function(event){ | |
//createWebview(form.input.value) | |
createBrowserWindow(form.input.value) | |
return false; | |
} | |
function createWebview(url){ | |
let webview = new WebView() | |
webview.setAttribute("autosize","on") | |
webview.setAttribute("nodeintegration","on") | |
webview.setAttribute("disablewebsecurity","on") | |
webview.setAttribute("webpreferences","allowRunningInsecureContent") | |
webview.src = url | |
webviews.appendChild(webview) | |
let tab = document.createElement("div") | |
tab.textContent = url | |
tab.target = webview | |
tabs.appendChild(tab) | |
} | |
function createBrowserWindow(url){ | |
let win = new BrowserWindow({ | |
width: 800, | |
height: 600, | |
y: 100, | |
x: 100, | |
webPreferences: { | |
webSecurity: false, | |
nodeIntegration: false | |
} | |
}) | |
win.setMenu(null) | |
win.on('closed', () => { | |
win = null | |
}) | |
view = new BrowserView({ | |
webPreferences: { | |
nodeIntegration: false | |
} | |
}) | |
win.webContents.openDevTools() | |
// Load a remote URL | |
win.loadURL(url) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment