Hello everyone! What is the correct method to copy text to clipboard. The method I tried returns the error: “Failed to create DataTransferProviders: invalid DataTransferProviders parameter.”
Script:
const string = "My string";
navigator.clipboard
.writeText(string)
.then(() => {
console.log("Text copied to clipboard!");
})
.catch((err) => {
console.error("Error copying text: ", err);
});