Created
January 7, 2019 18:40
-
-
Save vviikk/d218aa975adcd7a10b93ed2794ed8457 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 | |
}) | |
const ipcMain = require('electron').ipcMain; | |
ipcMain.on('url', function(event, data) { | |
console.log(data); | |
}); | |
// In the main process. | |
win = null | |
// }) const { BrowserView } = require('electron') | |
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 }) | |
console.log('creating'+ url) | |
view.webContents.loadURL(url) | |
} | |
const views = tabs.map(({url}) => createView(url, '', true)) | |
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; | |
} | |
const tabs = [ | |
{ | |
url: 'https://google.com' | |
}, | |
{ | |
url: 'https://web.whatsapp.com' | |
}, | |
{ | |
url: 'https://messenger.com' | |
} | |
] | |
function createBrowserView(url, title='', setAsMain = false){ | |
const view = new BrowserView({ | |
webPreferences: { | |
nodeIntegration: false | |
} | |
}) | |
const ipcRenderer = require('electron').ipcRenderer; | |
ipcRenderer.send('url',url) | |
if (setAsMain) win.setBrowserView(view) | |
view.setBounds({ x: 0, y: 50, width: 1000, height: 550 }) | |
console.log('creating'+ url) | |
view.webContents.loadURL(url) | |
//const views = tabs.map(({url}) => createView(url, '', true)) | |
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