You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Remote issues with clipboard and NativeImage #8151
Captured image from webview is copied into clipboard
Actual behavior
Crashes with error message
Uncaught TypeError: Error processing argument at index 0, conversion failure from [object Object]
How to reproduce
I am capturing a region of a webview object and then saving as an image (works pretty ok, although sometimes the image is empty), then I am trying to copy the NativeImage into clipboard, but it crashes
webview.capturePage(rect,image=>{constquality=90constfilename='image.jpg'constfullPath=path.join(__dirname,filename)fs.writeFile(fullPath,image.toJPEG(quality),(err)=>{// TODO: retry save if the image is 0 sizeclipboard.writeImage(image)})})
I can see the image on the disk, but the clipboard has never received it, always crashing
Yes, so in the code example, webview.capturePage returns NativeImage, which I am passing directly into clipboard.writeImage(image). Conversion to JPEG is only done to save the image to disk to make sure the file is valid.
You can wrap it in a nativeImage.createFromBuffer(image.getBitmap()) to workaround this.
This issue is happening because webview.capturePage is actually a remote method doing IPC so the value it calls back with is a remote nativeImage object. It does not seem like it is currently supported to pass these back into subsequent API calls.
Thank you for taking the time to report this issue and helping to make Electron better.
The version of Electron you reported this on has been superseded by newer releases.
If you're still experiencing this issue in Electron v4.2.x or later, please add a comment specifying the version you're testing with and any other new information that a maintainer trying to reproduce the issue should know.
I'm setting the blocked/need-info label for the above reasons. This issue will be closed 7 days from now if there is no response.
Uncaught Error: Could not call remote function 'anonymous'. Check that the function signature is correct. Underlying error: Error processing argument at index 0, conversion failure from #<Object>
Will be possible in Electron 6+ after #20825 is merged and backported.
<webview>.capturePage() will be returning a NativeImage instance correctly, which can then be passed to clipboard.writeImage() in the renderer process.
It's still sending data over IPC though, it's better to handle this in the main process as suggested by #8151 (comment)
Activity
kevinsawicki commentedon Dec 6, 2016
The argument to
writeImageneeds to be aNativeImageorStringfile path,image.toJPEG()returns aBuffer.Use
nativeImage.fromBuffer(image.toJPEG(quality))instead.http://electron.atom.io/docs/api/native-image/
bahmutov commentedon Dec 6, 2016
Yes, so in the code example,
webview.capturePagereturns NativeImage, which I am passing directly intoclipboard.writeImage(image). Conversion to JPEG is only done to save the image to disk to make sure the file is valid.kevinsawicki commentedon Dec 6, 2016
Whoops, sorry, misread that.
kevinsawicki commentedon Dec 6, 2016
You can wrap it in a
nativeImage.createFromBuffer(image.getBitmap())to workaround this.This issue is happening because
webview.capturePageis actually a remote method doing IPC so the value it calls back with is a remotenativeImageobject. It does not seem like it is currently supported to pass these back into subsequent API calls.[-]Cannot copy captured NativeImage to clipboard (crashes)[/-][+]Cannot copy remote NativeImage to clipboard[/+]bahmutov commentedon Dec 6, 2016
so far no luck, does not seem the image is placed into the clipboard. Is there a good tool to inspect the clipboard for Mac?
kevinsawicki commentedon Dec 6, 2016
I usually just launch
TextEditsince it supports pasting images.Can you try
clipboard.writeImage(nativeImage.createFromBuffer(image.toJPEG(1000)))instead?kevinsawicki commentedon Dec 6, 2016
clipboard.writeImage(nativeImage.createFromBuffer(image.toPNG()))works for me too.bahmutov commentedon Dec 6, 2016
Cool, both the above work arounds work, and the image can be pasted into Chrome email clients for example. Thank you very much for looking at this.
kevinsawicki commentedon Dec 6, 2016
Great to hear, you can avoid these workarounds if you run this from the main process.
In Main Processs
In Render Process
13 remaining items
(fix) Fix writing images to clipboard on Linux platforms
sofianguy commentedon Aug 9, 2019
Thank you for taking the time to report this issue and helping to make Electron better.
The version of Electron you reported this on has been superseded by newer releases.
If you're still experiencing this issue in Electron v4.2.x or later, please add a comment specifying the version you're testing with and any other new information that a maintainer trying to reproduce the issue should know.
I'm setting the
blocked/need-infolabel for the above reasons. This issue will be closed 7 days from now if there is no response.Thanks in advance! Your help is appreciated.
DuBistKomisch commentedon Aug 9, 2019
This is still an issue on 5.0.9:
at
renderer/api/remote.js:222miniak commentedon Oct 30, 2019
Will be possible in Electron 6+ after #20825 is merged and backported.
<webview>.capturePage()will be returning aNativeImageinstance correctly, which can then be passed toclipboard.writeImage()in the renderer process.It's still sending data over IPC though, it's better to handle this in the main process as suggested by #8151 (comment)