Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy to clipboard not working on all platforms #49

Open
nx10 opened this issue Jan 8, 2021 · 3 comments
Open

Copy to clipboard not working on all platforms #49

nx10 opened this issue Jan 8, 2021 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed JS client HTML/JS client issue

Comments

@nx10
Copy link
Owner

nx10 commented Jan 8, 2021

Copy to clipboard is confirmed not working in:

  • Safari 14.0.2 (macOS Big Sur 11.1)
  • VSCode webview (1.52.1)

Safari throws "NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission."

Maybe calling the clipboard API wrapped in the image load callback is not allowed?

It not working in the VSCode webview might be caused by IFrame security settings. (Needs further investigation)

The associated code is

httpgd/inst/www/httpgd.ts

Lines 486 to 502 in abe90b9

public copyPlotPNG() {
if (!navigator.clipboard) return;
const canvas = document.createElement('canvas');
document.body.appendChild(canvas);
canvas.width = this.plotParams.width / this.scale;
canvas.height = this.plotParams.height / this.scale;
const ctx = canvas.getContext('2d');
if (!ctx) return;
const img = new Image();
img.crossOrigin = 'anonymous';
img.onload = () => {
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
canvas.toBlob(blob => { if (blob) navigator.clipboard.write?.([new ClipboardItem({ 'image/png': blob })]) });
};
img.src = this.svgURL();
document.body.removeChild(canvas);
}

Thank you @psobolewskiPhD for the bug report.

@nx10 nx10 added bug Something isn't working JS client HTML/JS client issue labels Jan 8, 2021
@psobolewskiPhD
Copy link

Here's the error in JS Console on Big Sur Safari 14.0.2

Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
It flags:

N (anonymous function)
N rejectPromise
N write
f (anonymous function)

Specially line 416 of httpgd.js:
(_b = (_a = navigator.clipboard).write) === null || _b === void 0 ? void 0 : _b.call(_a, [new ClipboardItem({ 'image/png': blob })]); });
Specifically this:
_b.call(_a, [new ClipboardItem({ 'image/png': blob })])

@psobolewskiPhD
Copy link

In VSCode I tried to use the Webview Dev tools, but it just shows an iframe with httpgd http link in another iframe
image
The VSCode WebView issue could be related to:
microsoft/vscode#65452 (comment)
but the other keybindings (save, clear) work...

@nx10 nx10 added the help wanted Extra attention is needed label Feb 17, 2021
@nx10 nx10 mentioned this issue May 5, 2021
29 tasks
@jeffreyxparker
Copy link

Not working VSCode, Sublime, or Chrome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed JS client HTML/JS client issue
Projects
None yet
Development

No branches or pull requests

3 participants