¿Alguien puede decirme por qué lo siguiente no funciona? Disculpen cualquier error soy nuevo en todo esto
HTML
<webview id="wv1" src="https://www.github.com/" style="display:inline-flex; width:100%; height:140px" nodeintegration></webview> <script> var webview = document.getElementById('wv1'); webview.addEventListener('dom-ready', function() { webview.insertCSS('html,body{ background-color: #FF0000 !important;}') }); </script>Estoy tratando de hacerlo para que una vez que el contenido dentro de la vista web se haya cargado, el fondo cambie a rojo a través de CSS. Abierto a cualquier alternativa o ayuda con por qué lo anterior no funcionará.
Gracias
Funciona para mí usando la siguiente configuración, básicamente solo el inicio rápido de electrones
Ejecutar como electron index.js
const { app, BrowserWindow } = require('electron') const path = require('path') const url = require('url') let win function createWindow() { win = new BrowserWindow({ width: 800, height: 600 }) win.loadURL(url.format({ pathname: path.join(__dirname, 'index.html'), protocol: 'file:', slashes: true })) win.webContents.openDevTools() win.on('closed', () => { win = null }) } app.on('ready', createWindow) app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit() } }) app.on('activate', () => { if (win === null) { createWindow() } }) <webview id="wv1" src="https://www.github.com/" style="display:inline-flex; width:100%; height:140px" nodeintegration></webview> <script> var webview = document.getElementById('wv1'); webview.addEventListener('dom-ready', function () { webview.insertCSS('html,body{ background-color: #FF0000 !important;}') }); </script>Solo para estar seguro de que puede querer usar en lugar de dom-ready el DOMContentLoaded y en lugar de insertCss, insertRule.
var webview = document.getElementById('wv1'); webview.addEventListener('DOMContentLoaded', function() { webview.insertRule('html,body{ background-color: #FF0000 !important;}',1) });Sin embargo, si no funciona, es posible que desee intentar
webview.querySelector(body) !== nullDentro de la función.
espero que funcione.