'Copy to clipboard code in JavaScript doesn't work

I'm trying to write in javascript and I want to understand why it doesn't work? sample order code that I want to copy: 593004485164756431

when I copy to clipboard : 593004485164756500

I checked for an error in the console, there was no error, does the browser affect the error? i use firefox

this my code

                function copyToClipboard(text) {
                if (navigator.clipboard && window.isSecureContext) {
                    return navigator.clipboard.writeText(text)
                } else {
                    // text area method
                    let textArea = document.createElement("textarea")
                    textArea.value = text
                    // make the textarea out of viewport
                    textArea.style.position = "fixed"
                    textArea.style.left = "-999999px"
                    textArea.style.top = "-999999px"
                    document.body.appendChild(textArea)
                    textArea.focus()
                    textArea.select()
                    return new Promise((res, rej) => {
                        // here the magic happens
                        document.execCommand('copy') ? res() : rej()
                        textArea.remove()
                    })
                }
            }

on button

<img onclick="copyToClipboard({{ $result['code_order'] }})" style="width:20px;cursor:pointer;" src="{{ url('img/copy-solid.svg') }}"/>

I hope I can find the solution to this problem. Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source