0

I am using window clipboard for copying some link on my web app. On the local angular build, things are working fine. However on the prod --build, the browser's clipboard object seems to be unavailable.

This is my code:

window.navigator.clipboard.writeText(`${location.origin}${url}`).then(() => {
      this.loaderService.displaySnackbar('Link Copied Successfully.');
    }, (error) => {
      console.log('copy failed');
    });

which throws below error (only on deployed dist).

main.884d5aa69d5889e86016.js:1 ERROR TypeError: Cannot read property 'writeText' of undefined
    at t.onFeedLinkCopy (main.884d5aa69d5889e86016.js:1)
    at t.onMenuItemClick (main.884d5aa69d5889e86016.js:1)
    at main.884d5aa69d5889e86016.js:1

I am testing the code on same browser, so there is no browser version or any similar issue.

How can I get hold of the clipboard. Am I doing something wrong here. Please suggest.

Saurabh Tiwari
  • 4,002
  • 8
  • 36
  • 69
  • 1
    Here is a explanation of your issue - [navigator-clipboard-is-undefined](https://stackoverflow.com/questions/51805395/navigator-clipboard-is-undefined) – Abhijit Dec 12 '20 at 08:59

0 Answers0