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

Async/await firefox error #102

Closed
doglasbatista opened this issue Nov 23, 2018 · 1 comment
Closed

Async/await firefox error #102

doglasbatista opened this issue Nov 23, 2018 · 1 comment

Comments

@doglasbatista
Copy link

doglasbatista commented Nov 23, 2018

Hi,

I'm receiving the following error message on firefox 60.3.0esr version:
document.execCommand('cut'/'copy') was denied because it was not called from inside a short running user-generated event handler.

This is a sample of what I'm trying to do

import clipboard from 'clipboard-polyfill'

const response = await axios.get('/api/path')
clipboard.writeText(response)

I'm using clipboard-pollyfill 2.7.0 version

This code works as intended on google chrome 70.0.3538.77 version

@lgarron
Copy link
Owner

lgarron commented Nov 23, 2018

As the error message says, Firefox requires the clipboard API to be called inside a short-running event handler. await axios.get('/api/path') can be a relatively long round-trip. Chrome has a bit of a leniency period, but it will also fail on slow connections to your server.

The best option is either to prepare the data ahead of time, or show a messages to the user that you are preparing the data and asking them to trigger another action to actually copy the data.

See w3c/clipboard-apis#41 for proposals to handle delayed clipboard data in the future.

@lgarron lgarron closed this as completed Nov 23, 2018
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