Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Copy to clipboard fails, with error

A topic by penguinhermit created 10 days ago Views: 79 Replies: 3
Viewing posts 1 to 5

I'm trying to get my first game/application working on itch.io. One feature is a "copy to clipboard" which should copy a generated list of 9 emoji to the user's clipboard. It works fine on my local PC and browser, but when hosted on itch.io it fails with this error:

Failed to copy text: NotAllowedError: Failed to execute 'writeText' on 'Clipboard': The Clipboard API has been blocked because of a permissions policy applied to the current document. See https://googl/EuHzyv for more details.

When followed, that goo.gl link shows:

404. <ins>That’s an error.
</ins>
The requested URL was not found on this server. <ins>That’s all we know.</ins>

Is there a workaround?

Moderator moved this topic to Questions & Support
Moderator(+1)

(moved to the right category)

(+1)

I tested it, the copy button worked fine on Firefox and the itch app. But on Chrome it returned the error you mentioned.

I have a web app that also have a copy button, and it behaves the same way. But I do have fallback/workaround for this case, though not very elegant: which is just showing the text to be copied in a container, and then tell the user to manually ctrl + C it, if the copy button doesn’t works.


I found this hacky workaround, but haven’t tested it myself: https://stackoverflow.com/a/72239825

It involves creating <textarea> element, putting the text there, focusing and selecting its content, and then use document.execCommand('copy'); to copy it.

But it seems like Document.execCommand has already been deprecated.


The emojis generated on your app can still be selected and copied manually on Chrome though. Which I think is good enough.

I see, so it's a chrome error. That explains the google link. Yes, I have advised users to manually select and copy and paste, so that's good enough I think. Thank you.