Skip to content

fix: delegate clipboard-write and web-share to the player iframe - #332

Open
kh-ruslan wants to merge 1 commit into
ibrahimcesar:mainfrom
kh-ruslan:fix/iframe-allow-clipboard-write-web-share
Open

kh-ruslan wants to merge 1 commit into
ibrahimcesar:mainfrom
kh-ruslan:fix/iframe-allow-clipboard-write-web-share

Conversation

@kh-ruslan

Copy link
Copy Markdown

Summary

Adds clipboard-write and web-share to the player iframe's allow attribute so YouTube's in-player Copy link and Share controls work. The new list matches YouTube's official embed snippet exactly:

accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share

Fixes #331

Why

Permissions Policy grants clipboard-write and web-share to a cross-origin frame only when the embedding <iframe> delegates them. Without the tokens the player shows "Unable to copy link to clipboard" and Chrome logs a Permissions Policy violation (https://crbug.com/414348233). Mux's youtube-video-element had the identical gap, fixed in muxinc/media-elements#248.

Changes

  • src/lib/index.tsx: two tokens added to the hardcoded allow string.
  • src/lib/index.test.tsx: one test asserting both tokens are present after activation.

Risk

Low. Single attribute string change, no logic touched, backward compatible. Both tokens are standard Permissions Policy features supported by Chromium, Firefox and Safari; browsers that do not recognise a token ignore it.

Verification

npm run lint        # Checked 7 files, no issues
npm run type-check  # clean
npm test            # 55 passed
npm run build       # dist/index.es.js and dist/index.cjs carry the new allow string

@github-actions

Copy link
Copy Markdown
Contributor

πŸ‘‹ This pull request has been automatically marked as stale because it has been inactive for 30 days.

It will be closed in 7 days if no further activity occurs.

If you're still working on this PR, please:

  • Add a comment with your progress
  • Update the PR with recent changes
  • Rebase if needed

Thank you for your contribution! πŸ™

@github-actions github-actions Bot added the stale label Oct 19, 2026
@kh-ruslan

Copy link
Copy Markdown
Author

Rebased onto current main (29dd5ba). Still a single-commit change: two tokens added to the iframe allow string plus one test, matching YouTube's official embed snippet. Lint, type-check, the 55 tests and the build pass locally.

@ibrahimcesar this is my first contribution here, so the Actions workflows (PR Title Check, Coverage Tests, etc.) are waiting for your one-click approval before they can run. Happy to adjust anything if you'd like it done differently. Fixes #331.

@kh-ruslan
kh-ruslan force-pushed the fix/iframe-allow-clipboard-write-web-share branch from 209f2f7 to 29dd5ba Compare October 19, 2026 11:09
@github-actions github-actions Bot removed the stale label Oct 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

πŸ‘‹ This pull request has been automatically marked as stale because it has been inactive for 30 days.

It will be closed in 7 days if no further activity occurs.

If you're still working on this PR, please:

  • Add a comment with your progress
  • Update the PR with recent changes
  • Rebase if needed

Thank you for your contribution! πŸ™

@github-actions github-actions Bot added the stale label Nov 19, 2026
YouTube's in-player "Copy link" and "Share" controls call the Clipboard and
Web Share APIs from inside the cross-origin iframe. Permissions Policy grants
those features to cross-origin frames only when the embedding <iframe>
delegates them via its allow attribute, so with the current list the copy
button fails with "Unable to copy link to clipboard" and Chrome logs
"Permissions policy violation: The Clipboard API has been blocked".

Align the allow list with YouTube's official embed snippet, which includes
clipboard-write and web-share.
@kh-ruslan
kh-ruslan force-pushed the fix/iframe-allow-clipboard-write-web-share branch from 29dd5ba to d6d56e1 Compare November 23, 2026 12:25
@kh-ruslan

Copy link
Copy Markdown
Author

Still relevant, so keeping this open. Rebased onto current main (137dc61), no conflicts. It is still a single commit: two tokens added to the iframe allow string plus one test, matching YouTube's official embed snippet.

Checked locally after the rebase on Node 24: lint, type-check, the 55 tests and the build all pass, and both dist/index.es.js and dist/index.cjs carry the new allow string.

@ibrahimcesar two small things when you have a moment:

  • The Actions workflows are still waiting for first-time-contributor approval, so only the Snyk check has run.
  • If a review is not possible soon, adding the waiting-for-review label would stop the stale bot from flagging this every 30 days.

Happy to change anything. Fixes #331.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

iframe allow list omits clipboard-write and web-share, breaking the player's Copy link / Share controls

1 participant