0

Hi guys I am writing this code

    async function copyLink() {
        const myToken = Cookies.get("token");
        const linkAndToken = "somepage.com/earlyAccessPage/token?=" + myToken;
        try {
          await navigator.clipboard.writeText(linkAndToken);
          console.log("Page URL copied to clipboard");
        } catch (err) {
          console.error("Failed to copy: ", err);
        }
    }

      return (
        <div css={button} onClick={copyLink}>
          <span css={buttonText}>Copy&nbsp;Link</span>
        </div>
      );
    };

It should copy "linkAndToken" variable value to my clipboard. In local it work correct but in production it show error like "TypeError: Cannot read property 'writeText' of undefined". Help me correct this function for production

  • 3
    Does this answer your question? [How do I copy to the clipboard in JavaScript?](https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript) – Rehmat Jun 14 '20 at 15:11

0 Answers0