async function writeToClipboard(text) {
    // Error if we received the wrong kind of data.
    if (typeof text !== "string") {
        throw new TypeError(`Value provided must be a 'string', got '${typeof text}'.`);
    }

    document.addEventListener(
        "copy",
        function (e) {
            e.clipboardData.setData("text/plain", text);
            e.preventDefault();
        },
        { once: true }
    );
    document.execCommand("copy");
}
Copy text to clipboard and optionally clear it from the clipboard after one minute

@since 3.2.0

@param string text Text to copy
@return void