Created
January 7, 2019 21:33
-
-
Save vviikk/e82d119fa3018e070f39f9c7b50c76bf 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> | |
</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> | |
<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) | |
const init = config => { | |
} | |
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 | |
}) | |
///ipcMain.send() | |
// 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: 100, width: 1000, height: 550 }) | |
console.log('creating'+ url) | |
view.webContents.loadURL(url) | |
} | |
//const views = | |
let views; | |
const ipcMain = require('electron').ipcMain; | |
console.log('waiting for SITES') | |
ipcMain.on('SITES', function(event, tabs) { | |
//console.log('URL' + data); | |
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 webviews = document.querySelector(".webviews") | |
let tabs = document.querySelector(".tabs") | |
document.getElementsByTagName("form")[0].onsubmit = function(event){ | |
//createWebview(form.input.value) | |
createBrowserView(form.input.value) | |
return false; | |
} | |
function createBrowserView(url, title='', setAsMain = false){ | |
const ipcRenderer = require('electron').ipcRenderer; | |
const apps = [ | |
{ | |
url: 'https://google.com' | |
}, | |
{ | |
url: 'https://web.whatsapp.com' | |
}, | |
{ | |
url: 'https://messenger.com' | |
} | |
] | |
ipcRenderer.send('SITES',apps) | |
debugger; | |
console.log('sent') | |
//if (setAsMain) win.setBrowserView(view) | |
//view.webContents.loadURL(url) | |
//debugger | |
apps.forEach((app, idx) => { | |
debugger | |
let tab = document.createElement("div") | |
tab.textContent = app.url | |
//tab.target = webview | |
tabs.appendChild(tab) | |
console.log(idx) | |
}) | |
console.log('asd') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment