Closed YeYongFen closed 6 years ago
Hi @yyf1994gggg , thanks for reporting this and giving me the possible solution. BTW, could you please give me the link that I can reproduce the problem you mentioned? Thank you.
the error above appear in development environment ,maybe it will be fine In the production environment
I look up the doc, I found an easier way to do this contents.copyImageAt(x, y) && contents.downloadURL(url)
menu.append(new MenuItem({
label: i18n.t("Menu.copyImage"),
click: () => {
let webContent = this.webview.getWebContents();
webContent.copyImageAt(this.options.x,this.options.y)
},
}));
menu.append(new MenuItem({
label: i18n.t("Menu.saveImageAs"),
click: () => {
let webContent = this.webview.getWebContents();
webContent.downloadURL(this.options.srcURL)
},
}));
@yyf1994gggg Okay, I know the problem you're facing exactly. It's because you wanna load images from remote sites, the main BrowserWindow will serve files from origin: localhost
no matter it's in development or production mode, however. That is, you'll be denied to load any file from the remote site since it violates the CORS rule.
To conclude, the best way to load images into the BrowserWindow is to host them from local.
To the explanation aboved, I'm about to close the issue. Please don't be hesitated to ask me to reopen it if you've found another problem. Thank you!
when I copy image , new Iamge() throw a CROS error. and "save image " function does work. And I find a solution in brave-broswer project. maybe it can help you
https://electronjs.org/docs/api/web-contents#contentscopyimageatx-y
https://electronjs.org/docs/api/web-contents#contentscopyimageatx-y