Instantly share code, notes, and snippets.
RareScrap/index.html Secret
CreatedDecember 10, 2025 07:41
Save RareScrap/0a3fa1470f2c483f18f022ae3ce9b4e9 to your computer and use it in GitHub Desktop.
Incorrect Electron documentation showcase
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <metacharset="UTF-8"> | |
| <!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> | |
| <metahttp-equiv="Content-Security-Policy"content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'"> | |
| <title>Hello World!</title> | |
| </head> | |
| <body> | |
| <h1>Hello World!</h1> | |
| We are using Node.js<spanid="node-version"></span>, | |
| Chromium<spanid="chrome-version"></span>, | |
| and Electron<spanid="electron-version"></span>. | |
| <buttonid="myButton">Click Me!</button> | |
| <!-- You can also require other files to run in this process --> | |
| <scriptsrc="./renderer.js"></script> | |
| </body> | |
| </html> |
This file contains hidden or 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, ipcMain}=require('electron') | |
| constpath=require('node:path') | |
| functioncreateWindow(){ | |
| constmainWindow=newBrowserWindow({ | |
| width:800, | |
| height:600, | |
| roundedCorners:false,// Docs says that setting this property to false will prevent the window from being fullscreenable on macOS but it's not true | |
| frame:false, | |
| webPreferences:{ | |
| preload:path.join(__dirname,'preload.js') | |
| } | |
| }) | |
| mainWindow.loadFile('index.html') | |
| mainWindow.webContents.openDevTools() | |
| returnmainWindow | |
| } | |
| app.whenReady().then(()=>{ | |
| constmainWindow=createWindow() | |
| ipcMain.on("enable-fullscreen",()=>{ | |
| mainWindow.setFullScreen(true) | |
| }) | |
| app.on('activate',function(){ | |
| // On macOS 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() | |
| }) | |
| }) | |
| // Quit when all windows are closed, except on macOS. There, it's common | |
| // for applications and their menu bar to stay active until the user quits | |
| // explicitly with Cmd + Q. | |
| app.on('window-all-closed',function(){ | |
| if(process.platform!=='darwin')app.quit() | |
| }) |
This file contains hidden or 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
| { | |
| "name":"understood-gate-chop-vba1s", | |
| "productName":"understood-gate-chop-vba1s", | |
| "description":"My Electron application description", | |
| "keywords": [], | |
| "main":"./main.js", | |
| "version":"1.0.0", | |
| "author":"rarescrap", | |
| "scripts": { | |
| "start":"electron ." | |
| }, | |
| "dependencies": {}, | |
| "devDependencies": { | |
| "electron":"39.0.0" | |
| } | |
| } |
This file contains hidden or 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
| // import { contextBridge, ipcRenderer } from 'electron'; | |
| const{ contextBridge}=require('electron') | |
| const{ ipcRenderer}=require('electron') | |
| contextBridge.exposeInMainWorld("ipc",{ | |
| "enableFullscreen":()=>ipcRenderer.send("enable-fullscreen") | |
| }) |
This file contains hidden or 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
| constbutton=document.getElementById("myButton"); | |
| button.addEventListener("click",function(){ | |
| window.ipc.enableFullscreen() | |
| }); |
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment