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

HTML: "Copy link address" fails with "Document is not focused" #357

Open
benbucksch opened this issue Jan 8, 2025 · 3 comments
Open

HTML: "Copy link address" fails with "Document is not focused" #357

benbucksch opened this issue Jan 8, 2025 · 3 comments
Assignees

Comments

@benbucksch
Copy link
Collaborator

benbucksch commented Jan 8, 2025

Reproduction

  1. Open an HTML email
  2. Right-click on a link / URL
  3. Select "Copy link address" menu item
  4. Paste in another app, e.g. a text editor

Actual result

  • Nothing is copied
  • No error msg is visible to end user
  • Console shows error "NotAllowedError: Failed to execute 'writeText' on 'Clipboard': Document is not focused."
  • Stack trace
  at copyToClipboard (../../../../app/frontend/Shared/ContextMenu.ts:264:25)
  at copyLink (../../../../app/frontend/Shared/ContextMenu.ts:226:3)
  at menuItem (../../../../app/frontend/Shared/ContextMenu.ts:38:56)
  at catchErrors (../../../../app/frontend/Util/error.ts:60:11)
  at <object>.click (../../../../app/frontend/Shared/WebView.svelte:145:20)
...

Expected result

  • The URL is pasted
  • On Linux, the secondary clipboard is used (the clipboard where I explicitly copy and explicitly paste something, not the clipboard where every selection is copied and a mouse middle click pastes it)

Additional info

  • "Copy" on a selected text works, with the secondary clipboard, as expected
@benbucksch
Copy link
Collaborator Author

benbucksch commented Jan 11, 2025

PR #372 by Jeremy

@benbucksch
Copy link
Collaborator Author

benbucksch commented Jan 11, 2025

@jermy-c Have you tried focusing the right document? Given that writeText() is called by the frontend, it should probably be the frontend and not the webview that is focused. A simple document.documentElement.focus() - or similar - might be sufficient. Can you please investigate in this direction?

@jermy-c
Copy link
Collaborator

jermy-c commented Jan 13, 2025

I have tried:

  • document.documentElement.focus()
  • <webview>.focus()
  • window.focus()
  • webcontents.focus()

It be because the while the context menu is in the backend and while the function is executing it will focus on the window it is called.

Chrome

Document is not focused

This error happens in Chrome when there is delay in writing to clipboard and user is not focusing on the window.

https://medium.com/nerd-for-tech/navigator-clipboard-api-b96be187df5d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants