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

Paste shows warning in Google Chrome #2183

Closed
borremosch opened this issue Oct 9, 2020 · 6 comments
Closed

Paste shows warning in Google Chrome #2183

borremosch opened this issue Oct 9, 2020 · 6 comments

Comments

@borremosch
Copy link

monaco-editor version: 0.21.2
Browser: Chrome 86.0.4240.75
OS: Windows 10
Playground code that reproduces the issue: https://microsoft.github.io/monaco-editor/

Right clicking and choosing paste from the context menu shows a warning dialog stating microsoft.github.io wants to see text and images copied to the clipboard. Copying from the context menu or pasting through CTRL+V does not cause the warning to appear. This behavior does not seem to be present in older versions of Monaco.

@Pranomvignesh
Copy link
Contributor

Pranomvignesh commented Oct 9, 2020

  1. yes a prompt will appear if navigator.clipboard.readText is triggered

@borremosch I think that's how it works, Please refer this issue

This behavior does not seem to be present in older versions of Monaco.

I think this is because , paste in context menu is available only after 0.21.0
More over on accessing navigator clipboard's text using javascript , Browser will throw this prompt as a security measure

@borremosch
Copy link
Author

borremosch commented Oct 9, 2020

Shouldn't the prompt trigger only when the clipboard was not accessed through any user interaction? Since the clipboard access is following a mouse click I would expect the prompt to be skipped.

I think this is because , paste in context menu is available only after 0.21.0

That makes total sense

@Pranomvignesh
Copy link
Contributor

Monaco seems to use a custom context menu and not the native context menu of the browser. So it may look like a mouse click , but internally it is going to trigger a javascript function which in turn access the navigator.clipboard

Since the clipboard access is following a mouse click I would expect the prompt to be skipped.

Yes , I too wish pasting happens this way

@bpasero, Is it possible to modify the paste function without prompt? Now-a-days, Browser's native context menu does that without a prompt

NativeBrowserContextMenuPaste

@bpasero
Copy link
Member

bpasero commented Oct 10, 2020

The "Paste" action was not present in the editor menu before as far as I can tell, and now that we have it, the browser will show the warning, that is just a security feature of the browser. I am not sure what we can do here or what changed?

@Pranomvignesh
Copy link
Contributor

@bpasero As the browser's default context menu does paste without prompt there might be a way we can also implement it without that prompt. I thought Browser is using some API ( other than navigator ) to achieve this, In that case we can also use that API and do the paste action. But I'm not sure that kind of API exists.

The main problem here is the UX of the paste action.
The security prompt will be shown only for Context Menu Paste and not for Cmd/Ctrl + V
From the user's point of view , As both are doing the same thing, one is showing a warning and other doesn't , creates a confusion.

@alexdima
Copy link
Member

When right clicking in the editor, you don't get a native context menu, you see a custom context menu rendered with DOM nodes. That is why we can render custom actions, like rename, or go to definition etc. When clicking on Paste in the editor context menu, you are basically clicking on a DOM node from the browser's point of view. There is no paste event, there is a click event. In the implementation of that click we end up using browser API to read from the clipboard. That browser API will prompt the user and ask for permission.

When pressing ctrl+v in the editor, the browser generates a paste event. We read the data from the paste event, which does not create any user prompts.

The only way to get a context menu paste without a prompt is to give up our custom context menu and use the native browser context menu. We had that a very very long time ago and will not go in that direction ever again.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants