Description of the issue:
Bookmarklets that write to the clipboard using the JavaScript call ‘navigator.clipboard.writeText’ have stopped working properly in the latest release. The first bookmarklet clicked per window (not per tab) works as expected and then no other bookmarklet doing this will work in any tab in the window until the clipboard is loaded from a different source (e.g. copying text from a web page).
How can this issue be reproduced?
Create a bookmarklet with the URL: javascript:navigator.clipboard.writeText(“first text to paste”);
Create a second bookmarklet with the URL: javascript:navigator.clipboard.writeText(“second text to paste”);
Open a simple web page
Click the first bookmarklet
Observe that the clipboard contains the text “first text to paste”
Click the second bookmarklet
Observe that the clipboard still contains the text “first text to paste”
Expected result:
After step 6 above, the contents of the clipboard should be “second text to paste”
Additional Information:
Chrome Version 154.0.8037.93 (Official Build) (64-bit) does not have this issue so it appears to specific to the latest version of Brave.
Oops. I made the classic mistake of assuming that the code was correct because it had been doing what I wanted – for years in this case – in both Chrome and Firefox. Thank you for catching the single-quote vs double-quote error. I know several other languages and in all of them strings are defined with double-quotes. I’m just learning JavaScript and obviously was mislead by old habits.
Sorry, but both single and double quotes are valid string delimiters in JavaScript, so this is not the problem. I checked the ECMA standard to verify this.
How can this issue be reproduced?
The problem has changed behaviour with the latest release of Brave:
Brave 1.97.56 (Official Build) (64-bit)
Chromium: 155.0.8059.40
Unfortunately, there is no specific procedure that causes it and its behaviour appears to vary depending on the web page contents. The best I can figure out is something like this:
Click to run the first bookmarklet. This may or may not work
Click to run the second bookmarklet. This may or may not work, but is much less likely to work
Repeat 1, 2 & 3 as necessary. At some point, the clipboard contents will be incorrect
Expected result:
After each click of one of the bookmarklets, the clipboard should contain the data defined in the bookmarklet.
Sorry I can’t be more specific. I suspect a buffer overrun or uninitialized variable or ???
Trick: I view the clipboard contents by left-clicking in the address field and then right-clicking it. The clipboard contents appear in the “Paste and search for…” selection.