JavaScript Chrome: How to get the clipboard text?

I have this line of JavaScript, where I want to insert the clipboard data (text) instead of the variable clipText:

document.querySelectorAll('.lmt__textarea_container textarea')[0].value = 'clipText'

How can I do this?

(In KM I assign the content of system clipboard to %clipText%.)

In browser JS (Chrome, Safari), you should be able to access KM variables, which the Execute JS in Browser actions bind as name:value pairs in a read-only dictionary, which is bound in turn to the document object (under the key kmvar, thus document.kmvar)

If, for example, you have assigned the clipboard contents to a KM variable named ‘clipText’, then in the browser JS, you should be able to obtain its value by writing:

const strClip = document.kmvar.clipText;
4 Likes

Thanks. This solved my problem.