This is because:
This feature is available only in secure contexts (HTTPS) or with localhost.
As the Clipboard API is the modern way of accessing the clipboard instead of the old solution that used the
document.execCommand() so don't change your code. Instead try one of the following:
- Configure HTTPS for your local development URL.
- Temporarily disable the browser's security check for the test domain. To do this in Chrome visit
chrome://flags/and enable the Insecure origins treated as secure option and add the local domain as an exception.