Skip to content

Instantly share code, notes, and snippets.

@andreasdj
Created March 18, 2022 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreasdj/f33865f96f621d3695bf902e564aca4d to your computer and use it in GitHub Desktop.
Save andreasdj/f33865f96f621d3695bf902e564aca4d to your computer and use it in GitHub Desktop.
BrowserView Background Color Bug
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<title>Hello World!</title>
</head>
<body> <!-- You can also require other files to run in this process -->
<div id="Content"></div>
<script src="./renderer.js"></script>
</body>
</html>
const {app, BrowserWindow, BrowserView} = require('electron')
const path = require('path')
function createWindow () {
const mainWindow = new BrowserWindow({
width: 1000,
height: 800,
backgroundColor: '#55ccbb',
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
mainWindow.webContents.loadFile('index.html')
mainWindow.once('ready-to-show', () => {
const offScreen = new BrowserView()
mainWindow.addBrowserView(offScreen)
offScreen.setBounds({ x: -50, y: 0, width: 400, height: 700 })
offScreen.webContents.loadURL('https://figma.com')
offScreen.setBackgroundColor('#ff00ff')
const visible = new BrowserView()
mainWindow.addBrowserView(visible)
visible.setBounds({ x: 400, y: 0, width: 400, height: 700 })
visible.webContents.loadURL('https://figma.com')
visible.setBackgroundColor('#ff00ff')
})
}
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
{
"name": "aquatic-soda-inject-yqt3a",
"productName": "aquatic-soda-inject-yqt3a",
"description": "My Electron application description",
"keywords": [],
"main": "./main.js",
"version": "1.0.0",
"author": "aj3621",
"scripts": {
"start": "electron ."
},
"dependencies": {},
"devDependencies": {
"electron": "17.1.2"
}
}
// All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension.
window.addEventListener('DOMContentLoaded', () => {
document.getElementById("Content").innerHTML = Array(1000).fill("tenderer tontent").join(' ')
})
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// No Node.js APIs are available in this process because
// `nodeIntegration` is turned off. Use `preload.js` to
// selectively enable features needed in the rendering
// process.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment