Created
February 7, 2022 13:12
-
-
Save t57ser/ce254e6e2e828949809bf872ed4168b6 to your computer and use it in GitHub Desktop.
This file contains 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 } = require( "electron" ) | |
app.whenReady().then(()=>{ | |
let main = new BrowserWindow({ | |
"height" : 600, | |
"width" : 800 | |
}) | |
main.loadURL( "https://www.youtube.com" ) | |
main.webContents.on( "did-finish-load", ()=>{ | |
let iframe = main.webContents.mainFrame.frames[ 0 ] | |
let injection = "new Promise(( resolve )=>{ resolve('hello') })" | |
let handler = ( result ) => { console.log( result ) } | |
//this code does not evaluate the same: | |
iframe.executeJavaScript( injection ).then( handler ) //returns "{}" | |
main.webContents.executeJavaScript( injection ).then( handler ) //returns "hello" | |
}) | |
}) |
This file contains 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
{ | |
"main": "main.js", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"devDependencies": { | |
"electron": "17.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just to outline the potentially obvious...
This gist only works and reproduces the bug if the URL on line 10 meets the following criteria...:
* - This is based on my personal understanding of the
executeJavaScript
method. I believe it can be executed without having anything loaded in the iframe