Copy texts to clipboard

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);
  });

Would you try with the following code?

const text = “My string”;
navigator.clipboard.writeText({ “text/plain”: text }).then(…);

https://developer.adobe.com/xd/uxp/uxp/reference-js/Global%20Members/Data%20Transfers/Clipboard/#writetext

Perfect! @mykim thanks for pointing me in the right direction.