otacke / h5p-structure-strip

MIT License
2 stars 6 forks source link

cannot copy to clipboard on localhost #57

Closed rezeau closed 9 months ago

rezeau commented 9 months ago

When using this H5P content on a localhost machine, when trying to copy to clipboard, getting error message "Your text could not be copied to the clipboard" Browser console shows "Uncaught TypeError: navigator.clipboard is undefined"

otacke commented 9 months ago

What browser are you using? What's its permission state for accessing the clipboard?

rezeau commented 9 months ago

Problem happens on Firefox, Chrome and Edge. But only locally, things are OK if I put my structure strip content online. Don't know how to check "permission state for accessing the clipboard".

otacke commented 9 months ago

Sorry, I cannot reproduce this at all. Browser support for navigator.clipboard is fine (https://caniuse.com/?search=navigator.clipboard). I'd not know why running on localhost would make a difference - in fact running on localhost should lead browsers to allow clipboard access (if it's triggered by a user action, and it is).

You may want to check permissions using navigator.permissions.query({name: 'clipboard-write'}).then((result) => { console.log(result.state) }); inside the H5P iframe context. Might give you denied.

You can also check what permission (or rejection) your local server sets (via some Content-Security-Policy) that might interfere or what the H5P integration sets onto iframes within the allow attribute. You could check whether your situation changes if that list contains clipboard-write.

This is not an issue with the content type code. In fact, it has a guard to detect that navigator.clipboard is not available and the text can therefore not be copied to the clipboard.

rezeau commented 9 months ago

Thanks for looking into this, @otacke I have just tested the Structure strip h5p content on my local computer in Lumi, and it's working as expected. This means that---as you suggest---some kind of Content-Security-Policy is enforced in the parameters of my local server (Wampserver). I will continue my investigations and report. Happy New Year 2024!

otacke commented 9 months ago

Happy New Year 2024 to you as well! Please let me know if you find out something. It's really an edge case, but I could try to query for more information when navigator.clipboard is not available and add a more specific error message.