microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.39k stars 28.62k forks source link

Clipboard access in webviews in Codespaces #115935

Open Tyriar opened 3 years ago

Tyriar commented 3 years ago

Right now using navigator.clipboard gets rejected inside a webview editor in a Codespace.

mjbvz commented 3 years ago

@Tyriar I just tested this in Chrome on GitHub.dev using an extension with creates a webview that runs:

setInterval(async () => {
    try {
        const c = await navigator.clipboard.readText();
        console.log(c)
    } catch (e) {
        console.error(e);
    }
}, 1000);

This fails if the webview is not focused but works properly when the document is focused

@Tyriar Are you still running into this? If so, can you share more details about how to reproduce

Tyriar commented 3 years ago

Codespaces had blocked SharedArrayBuffer due to not including the needed headers, I haven't used Luna Paint in it for a month or so so not sure

mjbvz commented 3 years ago

@Tyriar Did you get a chance to test this now that Luna Paint is running on web?

Tyriar commented 3 years ago

Can't test yet as I get a CSP problem when I try to load in github.dev/codespaces

Refused to connect to 'https://....loca.lt/package.json' because it violates the following Content Security Policy directive: "connect-src 'self'

Need to publish first

Tyriar commented 3 years ago

Got it working by installing the vsix, both copy and paste don't work in codespaces and there are no errors in the console when I do them.

Tyriar commented 3 years ago

It would be nice to get some testing around clipboard access in custom webviews as it's broken several times now

mjbvz commented 3 years ago

What browser are you using? A minimal example works fine for me in chrome.

However on safari I see:

The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission

There is never a visible prompt so I'm not sure what safari needs here

Tyriar commented 3 years ago

This was in latest Edge on Windows