question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to copy database to clipboard in Chome

See original GitHub issue

When trying to save my DB to the clipboard in this page, I press the button, the alert box comes up saying Copied database to clipboard but nothing is actually saved to the clipboard.

In the console the following error occurs:

Uncaught (in promise) DOMException: Document is not focused.

It works fine in Firefox and Safari, but not Chrome.

I don’t understand the error, if I’m pressing the button -> the button is focused -> the document should be focused too no? So what’s up?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
frzyccommented, Sep 10, 2021

@Pustur Sorry for the late reply, I had to prioritize time on more critical features. What a surprise for me to find the solution already waiting for me. The problem is resolved as of v6.0.13.

If you want more up-to-date responses to bugreports, I’ll advice you to join the Genshin Optimizer Discord, where I stage most of the feature requests/bugreports/discussions.

Thanks a lot for your help!

0reactions
Pusturcommented, Sep 10, 2021

Ok I think I understand the problem now.

In this code:

https://github.com/frzyc/genshin-optimizer/blob/ce5919de268b61179c811e0882b57951170f06a0/src/Settings/SettingsDisplay.tsx#L93-L94

You try to copy the DB to the clipboard and then alert right after it. The alert is actually the thing that’s responsible for the error! It basically steals the focus from the document so the clipboard operation fails. (apparently this focus problem only occurs on Chrome + macOS for some reason)

Instead the correct code would be:

navigator.clipboard.writeText(JSON.stringify(exportGOOD(dbStorage)))
  .then(() => alert("Copied database to clipboard."))
  .catch(console.error)

So the alert is only shown once the clipboard has been written to successfully.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix Copy and Paste Not Working in Chrome - Technipages
If you can't use the copy-paste option in Chrome, disable your extensions, clear the cache and update the browser. On the other hand, ......
Read more >
Your Browser Can't Access the Clipboard [Multiple Devices ...
The quickest way to fix this issue is to check if clipboard copying works in a different browser. Alternatively, you can try using...
Read more >
Unable to paste links in chrome text boxes - Google Support
The workaround is instead of tapping on Copy icon you need to tap on Share icon. And, tap on the "Copy Link" icon...
Read more >
Unblocking clipboard access - web.dev
Async Clipboard API simplifies permissions-friendly copy and paste.
Read more >
Copy to Clipboard in Chrome Extension - Stack Overflow
I'm making an extension for Google Chrome and I have hit a snag. I need to copy a readonly textarea's content to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found