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

Web: cannot copy/cut/paste in webviews using keyboard #106383

Closed
bpasero opened this issue Sep 10, 2020 · 4 comments
Closed

Web: cannot copy/cut/paste in webviews using keyboard #106383

bpasero opened this issue Sep 10, 2020 · 4 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority insiders-released Patch has been released in VS Code Insiders verified Verification succeeded web Issues related to running VSCode in the web webview Webview issues

Comments

@bpasero
Copy link
Member

bpasero commented Sep 10, 2020

Steps to Reproduce:

  1. open https://vscode-web-test-playground.azurewebsites.net/?enter=true
  2. open a markdown file
  3. add <input> element
  4. open preview
  5. try to cut/copy/paste in the input field

=> 🐛 it does not work

I think this only reproduces in a built version of VSCode web, not running out of sources. Using bisect I found the commit range to be this: e7920dc...3bc3f95

My guess would be: 7e5937d

@bpasero bpasero added bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority webview Webview issues web Issues related to running VSCode in the web labels Sep 10, 2020
@mjbvz
Copy link
Collaborator

mjbvz commented Sep 10, 2020

It seems to work for me when building from main with yarn web. Not sure what is different about that

In both cases however, we are not using our custom copy command. Here's what happens:

  1. User presses cmd+c in webview
  2. We intercept the keypresses in the webview and send them back to VS Code
  3. We then handle the keypress in our keybindings service.
  4. However on web, the copy command lacks an actual keybinding:
    // since browsers do that for us and it avoids security prompts
  5. This means we never resolve a keybinding for cmd+c

@alexdima Any thoughts on how best to handle this case? Does the comment in clipboard.ts still apply?

@alexdima
Copy link
Member

@mjbvz Yes, that is intentional. In browsers we don't want to ship with keybindings for cmd+c,cmd+v or cmd+x. We want browsers to execute their default action, we don't call preventDefault() and then browsers will invoke copy/paste/cut events without a security prompt. If we were to use a keybinding, we would have to go through clipboardService, which goes through the navigator clipboard API, which is not fully implemented in Firefox (so cmd+v will no longer work there at all) and which prompts in other browsers.

Long story short, my recommendation is that on the web you also do not capture cmd+c/cmd+v/cmd+x and allow the browser to generate copy/paste/cut events and add listeners for these events.

@mjbvz
Copy link
Collaborator

mjbvz commented Sep 14, 2020

Thanks for the background @alexdima!

I previously added special logic that calls preventDefault for copy/paste: 7e5937d

We need this on desktop to prevent double pasting but I will remove the call to preventDefault on web

@mjbvz mjbvz closed this as completed in e13875b Sep 14, 2020
@mjbvz mjbvz added this to the September 2020 milestone Sep 14, 2020
@bpasero bpasero added the verified Verification succeeded label Sep 15, 2020
@bpasero
Copy link
Member Author

bpasero commented Sep 15, 2020

Thanks, verified in https://vscode-web-test-playground.azurewebsites.net/?enter=true with todays build.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority insiders-released Patch has been released in VS Code Insiders verified Verification succeeded web Issues related to running VSCode in the web webview Webview issues
Projects
None yet
Development

No branches or pull requests

4 participants
@bpasero @alexdima @mjbvz and others