Created
January 7, 2019 21:52
-
-
Save vviikk/345c59fd934252ef83486cd3764f659b 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; | |
} | |
/** | |
* Patches window.Notification to: | |
* - set a callback on a new Notification | |
* - set a callback for clicks on notifications | |
* @param createCallback | |
* @param clickCallback | |
*/ | |
function setNotificationCallback(createCallback, clickCallback) { | |
const OldNotify = window.Notification; | |
const newNotify = (title, opt) => { | |
createCallback(title, opt); | |
const instance = new OldNotify(title, opt); | |
instance.addEventListener('click', clickCallback); | |
return instance; | |
}; | |
newNotify.requestPermission = OldNotify.requestPermission.bind(OldNotify); | |
Object.defineProperty(newNotify, 'permission', { | |
get: () => OldNotify.permission, | |
}); | |
window.Notification = newNotify; | |
} | |
setNotificationCallback(notifyNotificationCreate, notifyNotificationClick); | |
// check for notifications support | |
// you can omit the 'window' keyword | |
if (window.webkitNotifications) { | |
console.log("Notifications are supported!"); | |
} | |
else { | |
console.log("Notifications are not supported for this Browser/OS version yet."); | |
} | |
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