Skip to content

Instantly share code, notes, and snippets.

@mjbvz
Created August 3, 2020 22:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mjbvz/ec43f97cc063b635e55d4bbdd8b2d73b to your computer and use it in GitHub Desktop.
Save mjbvz/ec43f97cc063b635e55d4bbdd8b2d73b to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<link rel="stylesheet" type="text/css" href="./styles.css">
</head>
<body>
<script>
require('./renderer.js')
</script>
</body>
</html>
// Modules to control application life and create native browser window
const {app, BrowserWindow, session} = require('electron')
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
webviewTag: true
}
})
// and load the index.html of the app.
mainWindow.loadFile('index.html')
// intercept requests from main thread
const sess = session.fromPartition('test-part');
sess.webRequest.onBeforeRequest(async (details, callback) => {
console.log(details);
callback({})
});
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.
const webview = document.createElement('webview');
webview.setAttribute('partition', 'test-part');
document.body.appendChild(webview);
webview.style = 'width: 300px; height: 300px; background: hotpink;';
webview.setAttribute('src', `data:text/html,<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<link rel="stylesheet" type="text/css" href="./styles.css">
</head>
<body>
<script>
setInterval(() => {
const img = document.createElement('iframe');
img.src = 'http://example.com/'
document.body.appendChild(img);
}, 2000)
</script>
</body>
</html>`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment