Skip to content

Instantly share code, notes, and snippets.

@potato4d
Created November 15, 2016 07:25
Show Gist options
  • Save potato4d/5ba0989a2a2bc738143af79fd2d2e0b0 to your computer and use it in GitHub Desktop.
Save potato4d/5ba0989a2a2bc738143af79fd2d2e0b0 to your computer and use it in GitHub Desktop.
ElectronのWebviewにexecuteJavaScriptを利用した場合のコールバックについて ref: http://qiita.com/potato4d/items/9261908aba01f29c6f5f
const $ = e=>document.querySelector(e);
const webview = $("webview");
webview.addEventListener("did-stop-loading", ()=>{
webview.executeJavaScript(
`color:{$("#col_channels_bg").css("backgroundColor")}`,
false,
function(color){
console.log(color); // rgb(100, 100, 100);
// 決してcolor.colorではなく、colorでアクセスすることになるので注意
}
);
});
const $ = e=>document.querySelector(e);
const webview = $("webview");
webview.addEventListener("did-stop-loading", ()=>{
webview.executeJavaScript(
`return $("#col_channels_bg").css("backgroundColor")`,
false,
function(color){
console.log(color);
}
);
});
webview.openDevTools();
Uncaught SyntaxError: Illegal return statement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment