Skip to content

Replaced document exec Command ("copy"); #16604

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gmarav05
Copy link

Replaced deprecated document.execCommand in utils.ts with modern Clipboard.

issue no #16584

Replaced document.execCommand('copy') with navigator.clipboard.writeText(str) for modern, secure clipboard handling.

@gmarav05 gmarav05 requested a review from a team as a code owner June 24, 2025 02:44
@istio-policy-bot
Copy link

😊 Welcome! This is either your first contribution to the Istio documentation repo, or
it's been a while since you've been here. A few things you should know:

  • You can learn about how we write and maintain documentation, our style guidelines,
    and the available web site features by visiting Contributing to the Docs.

  • In the next few minutes, an automatic preview of your change will be built with
    a full copy of the istio.io website. You can find this preview by clicking on
    the Details link next to the deploy/netlify entry in the status section of this
    page.

  • We care about quality, so we've put in place a number of checks to ensure our documentation
    is top-notch. We do spell checking, sanitize the Markdown, ensure all hyperlinks point to a
    valid location, and more. If your PR doesn't pass one of these checks, you'll see a red X in the
    lint_istio.io entry in the status section. Click on the Details link to get a list of the
    problems with your PR. Fix those problems and push an update; this will automatically re-run the
    tests. Hopefully this time everything will be perfect!

  • Once your changes are accepted and merged into the repository, they will initially show up
    on https://preliminary.istio.io. The changes will be published to https://istio.io
    the next time we do a major release (which typically happens every 3 months or so).
    To publish them sooner, add a cherrypick/release-x.xx label, where x.xx is the current
    release of Istio.

Thanks for contributing!

Courtesy of your friendly welcome wagon.

Copy link

linux-foundation-easycla bot commented Jun 24, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@istio-testing istio-testing added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. needs-ok-to-test labels Jun 24, 2025
@istio-testing
Copy link
Contributor

Hi @gmarav05. Thanks for your PR.

I'm waiting for a istio member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@craigbox
Copy link
Contributor

/ok-to-test

@istio-testing istio-testing added ok-to-test Set this label allow normal testing to take place for a PR not submitted by an Istio org member. and removed needs-ok-to-test labels Jun 24, 2025
@craigbox
Copy link
Contributor

Please now show some evidence of before/after testing everywhere this code it called.

Tip: use the Netlify deploy preview link under Checks.

Copy link
Member

@AritraDey-Dev AritraDey-Dev left a comment

Choose a reason for hiding this comment

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

The issue might seem like it’s just about replacing that particular line, but if you’ve researched the implementation, you’ll notice there are other places in the function where document is used for selection and fallback logic.
When switching to navigator.clipboard.writeText, you don’t need any of the document-based selection or textarea logic—so the whole function should be refactored, not just that single line

@gmarav05
Copy link
Author

gmarav05 commented Jun 24, 2025

should we refactor that for entire codebase? bro @AritraDey-Dev all tests are passing correctly?

src/ts/utils.ts Outdated
@@ -53,7 +53,7 @@ function copyToClipboard(str: string): void {
sel.addRange(oldSelection);
} else {
el.select(); // Select the <textarea> content
document.execCommand("copy"); // Copy - only works as a result of a user action (e.g. click events)
navigator.clipboard.writeText(str); // Copy - only works as a result of a user action (e.g. click events)
Copy link
Contributor

Choose a reason for hiding this comment

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

The indenting no longer matches.

@gmarav05 gmarav05 requested a review from AritraDey-Dev June 25, 2025 10:23
Copy link
Member

@dhawton dhawton left a comment

Choose a reason for hiding this comment

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

Please refactor this function. You don't most of the lines in there in the implementation you did. IE: no longer need to create an element, place the string in that element, then select that element, etc.

Copy link
Member

@AritraDey-Dev AritraDey-Dev left a comment

Choose a reason for hiding this comment

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

@gmarav05,Please read this comment: #16604 (review) — Daniel also mentioned the same concern.You need to remove the unused document reference from the code, as it’s no longer required if you're using navigator.

@BHAVISHYA2005
Copy link

@gmarav05 ? Please do as mentioned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Set this label allow normal testing to take place for a PR not submitted by an Istio org member. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants