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: iFrame fix #2826

Merged
merged 1 commit into from
Apr 3, 2021

Conversation

RunDevelopment
Copy link
Member

This fixes #2824.

If clipboard.writeText fails for any reason, the implementation will now use the fallback method before. This should work around the permission problem in iFrames. I am aware that what I just said means: "this will circumvent browser security measurements," but there's not much I can do about it. The API that is supposed to be used to request access (in a secure way) is still a working draft and only supported by one browser engine.

Even though libraries like clipboard.js only use the fallback method, I think we should still keep clipboard.writeText. The fallback uses deprecated non-standard methods, so I believe that it's a good idea to have clipboard.writeText around in case a browser removes execCommand in the future.

@github-actions
Copy link

JS File Size Changes (gzipped)

A total of 1 files have changed, with a combined diff of +1 B (+0.1%).

file master pull size diff % diff
plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js 711 B 712 B +1 B +0.1%

Generated by 🚫 dangerJS against b4a7bd4

@@ -63,7 +63,10 @@
/** @param {CopyInfo} copyInfo */
function copyTextToClipboard(copyInfo) {
if (navigator.clipboard) {
navigator.clipboard.writeText(copyInfo.getText()).then(copyInfo.success, copyInfo.error);
navigator.clipboard.writeText(copyInfo.getText()).then(copyInfo.success, function() {
Copy link

@sohamsshah sohamsshah Mar 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good 👍
Was curious that will adding error logging/catching be good to have with promises?

Thank you :)

@RunDevelopment RunDevelopment merged commit 01b7b6f into PrismJS:master Apr 3, 2021
@RunDevelopment RunDevelopment deleted the issue2824 branch April 3, 2021 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants