Im working with electron, i need to return value from executeJavaScript like below, anyway to get value of body? thanks for read
let mainWin;
function createMainWin(){
mainWin = new BrowserWindow({
width: 1920,
height:1080,
backgroundColor:'#ccc',
title:'Test',
webPreferences: {
nativeWindowOpen: true,
}
});
mainWin.loadURL('https://example.com');
mainWin.webContents.executeJavaScript(`
var body = document.querySelector('body').innerHTML;//value need to get
`
)
mainWin.webContents.openDevTools();
}
Aparently, as I'm seeing in the docs, you can get it with a then function.
let mainWin;
function createMainWin(){
mainWin = new BrowserWindow({
width: 1920,
height:1080,
backgroundColor:'#ccc',
title:'Test',
webPreferences: {
nativeWindowOpen: true,
}
});
mainWin.loadURL('https://example.com');
mainWin.webContents.executeJavaScript(`
document.querySelector('body').innerHTML; //value need to get
`).then( (result) => {
console.log(result);
})
mainWin.webContents.openDevTools();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With