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

Links which copy things to clipboard don't always work due to lack of user activation #18

Open
richardmcmillen opened this issue May 7, 2022 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@richardmcmillen
Copy link
Contributor

richardmcmillen commented May 7, 2022

I found this random page you can see the issue from https://github.github.io/clipboard-copy-element/examples/

  1. have something in your clipboard - abc for example
  2. find a button/link which adds something to your clipboard - eg. xyz
  3. click the button/link with rango
  4. paste clipboard contents to see what is in it.

Result will be abc, when the desired contents is xyz.

When rango receives a request and performs its action, before it writes the response message it could inspect the clipboard again and if it isn't still the original request then send the current contents back to talon in the response object hopefully allowing Talon to set this as clipboard contents and not the original content before the action.

@david-tejada
Copy link
Owner

This one is interesting. I thought this type of buttons didn't work because they needed user interaction. If you open the devtools and try to click the button with rango you get Uncaught (in promise) DOMException: Clipboard write was blocked due to lack of user activation.. The funny thing is that this only happens the second time. So it might be useful to implement what you suggest.

@david-tejada david-tejada added the bug Something isn't working label May 7, 2022
@david-tejada david-tejada self-assigned this May 7, 2022
@richardmcmillen
Copy link
Contributor Author

It is interesting, I can also see the issue whenever I haven't interacted with a page for some time and then try to use the rango hint. So it can also fail on the first attempt.

I also don't get the error whenever I have just clicked the mouse manually (anywhere on the screen) just before issuing the command to rango, I guess this would count as recent user activation.

@richardmcmillen
Copy link
Contributor Author

philc/vimium#2521
This issue and the various issues linked off it are full of people complaining about firefox copy issues in Vimium.

@david-tejada
Copy link
Owner

david-tejada commented May 12, 2022

Yeah, I'll implement it but I don't think we are going to get consistent behavior.

I don't think that vimium issue has anything to do with this. We do have consistent copying/pasting to the clipboard, we do that for every command

@david-tejada
Copy link
Owner

I solved this one but as anticipated we still get the DOMException most of the time. I think we can leave this issue open for anyone that bumps into that issue but change the title to reflect what's actually happening

@david-tejada david-tejada changed the title Links which copy things to clipboard don't work as Talon resets clipboard to what it was before the action Links which copy things to clipboard don't always work due to lack of user activation May 15, 2022
@david-tejada
Copy link
Owner

I tried to catch the error to warn the user when it fails by listening to window.onerror but that doesn't seem to work for DOMExceptions

@david-tejada
Copy link
Owner

In Chrome this never works because I have to send the response back to talon before I execute the command. Since this really works anyway I don't think it's a big issue

@david-tejada
Copy link
Owner

I've thought of a way to partially solve this by handling known cases. For example, github uses a web component called clipboard-copy. I would need to intercept clicks to these elements and copy the value to the clipboard the same way I do for copy link. This case seems easy enough. I suspect other cases will be more complex. If you find more of these cases post them here to see how I could handle them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants