I have a site which is accessed by webview app through URL. On my site I have made the function by which when you click on copy option then function trigger which is copy the current URL.
My Function code is:
const copyURL = () => {
const shareURL = window.location.origin;
navigator.clipboard.writeText(shareURL);
}
On HTML part button code is:
<button type="button" onClick={this.copyURL}>COPY</button>
I have tested that it is working perfectly on site. But when I have tested this on my app, URL will not copy.
Further I have tested the logcat after click on copy button this error shows:
"Uncaught TypeError: Cannot read property 'writeText' of undefined, source: https://myappurl/static/js/125.c7h7jd24.chunk.js"
I have searched a lot regrading this but not getting any success. Only one question which people have interacted with positive answers is this Clipboard API call throws NotAllowedError without invoking onPermissionRequest() but I have not get success in this also.
Can anyone share the correct approach for achieve this. I am sure that many of the people are suffering and still not get the answer. May be this will help us if anyone share the answer.
Thanks in advance for the help and support.