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

Copy to clipboard not working for interactive examples #10909

Closed
3 tasks done
tannerdolby opened this issue Apr 13, 2024 · 2 comments · Fixed by #10910
Closed
3 tasks done

Copy to clipboard not working for interactive examples #10909

tannerdolby opened this issue Apr 13, 2024 · 2 comments · Fixed by #10910
Labels
needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened.

Comments

@tannerdolby
Copy link
Contributor

tannerdolby commented Apr 13, 2024

Summary

The copy-to-clipboard logic is failing in the interactive example <iframe> due to lack of clipboard-write permissions for the Clipboard API.

To use the API in iframes, you need to enable it with Permissions Policy, which defines a mechanism that allows for selectively enabling and disabling various browser features and APIs. Concretely, you need to pass either or both of clipboard-read or clipboard-write, depending on the needs of your app.

URL

Reproduction steps

  1. Go to https://developer.mozilla.org/en-US/docs/Web/CSS/clip-path
  2. Click into one of the clip-path demo values, then click the copy-to-clipboard icon
  3. See error in console regarding lack of permissions
Screen Shot 2024-04-13 at 1 50 05 AM

Expected behavior

Expected content to be copied to clipboard within interactive examples

Actual behavior

Fails to copy content to clipboard and logs error to the browser console

Device

Desktop

Browser

Chrome

Browser version

Stable

Operating system

Mac OS

Screenshot

copy-to-clipboard-iframe-error.mov

Anything else?

No response

Validations

@github-actions github-actions bot added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Apr 13, 2024
@skyclouds2001
Copy link
Contributor

skyclouds2001 commented Apr 14, 2024

maybe we could make the {{EmbedInteractiveExample}} macros able to passing a parameter to specified allow attribute on the <iframe> element, just like the {{EmbedLiveSample}} does

https://github.com/mdn/yari/blob/main/kumascript/macros/EmbedLiveSample.ejs

@tannerdolby
Copy link
Contributor Author

tannerdolby commented Apr 16, 2024

@skyclouds2001 that could be an option, since the EmbedLiveSample macro supports a parameter for allowed features ($6) it makes sense that the EmbedInteractiveExample macro might do something similar. I'm just not sure if the interactive examples need any other permissions currently other than clipboard API. I added allow="clipboard-write" directly to the <iframe> in EmbedInteractiveExample.ejs for my initial PR (#10910) to quickly validate that the copy-to-clipboard worked again in interactive examples without having to update the actual EmbedInteractiveExample() macro calls throughout the various pages.

I searched mdn/content and found 1256 results in 1253 files of EmbedInteractiveExample( which would mean doing a mass search-and-replace to add a third argument with the "clipboard-write" permission, that is assuming all the interactive examples have code snippets which can be copied to clipboard. If the mdn folks are cool with that extra work of adding another parameter to the EmbedInteractiveExample macro to account for allowed features and updating those 1253 files in mdn/content then I can update my PR here to reflect that and submit one in mdn/content, otherwise I think simply adding the clipboard-write permission to the iframes directly gets the job done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants