Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Electron Fiddle Gist
<!DOCTYPE html>
<meta charset="UTF-8">
<title>Context Bridge Example</title>
<link rel="stylesheet" type="text/css" href="./styles.css">
<main class="app">
<button onclick="">Enter fullscreen</button>
<button onclick="">Exit fullscreen</button>
// You can also require other files to run in this process
// Modules to control application life and create native browser window
const {app, BrowserWindow, ipcMain} = require('electron')
const path = require('path')
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
allowRunningInsecureContent: false,
contextIsolation: true,
enableRemoteModule: false,
nodeIntegration: false,
sandbox: true,
preload: path.join(app.getAppPath(), 'preload.js'),
// and load the index.html of the app.
// Open the DevTools.
// mainWindow.webContents.openDevTools()
ipcMain.handle('setFullscreen', (event, flag) => {
if (mainWindow) {
// 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.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) {
const { ipcRenderer, contextBridge } = require('electron')
setFullscreen: (flag) => ipcRenderer.invoke('setFullscreen', flag),
.app {
text-align: center;
margin: 10rem;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.