Subroutine action to search rendered web page for text string

Hello,

ChatGPT provided the following JavaScript code to search for rendered text in any web page. It works very well in a Keyboard Maestro action. But I would like to convert it into a subroutine action. I've been stuck on converting it into a subroutine for awhile now. This is probably something simple that I'm not getting.

Execute a JavaScript in Google Chrome Action (v10.2)

Execute a JavaScript in Google Chrome.kmactions (1.5 KB)

Thanks in advance.
ChrisQ

Update: The syntax to get KM variable in my subroutine was incorrect, it was missing 'document'.

https://wiki.keyboardmaestro.com/actions/Execute_a_JavaScript_in_Browser?redirect=1#:~:text=or%20specific%20clipboard.-,Using%20Keyboard%20Maestro%20Variables,-JavaScript%20in%20browsers

1 Like