Why can't I do this

You probably can do it. You're just not returning any value from it yet, and need to prefix your querySelector expression with return.

See, for example:

Extract text from a website - Questions & Suggestions - Keyboard Maestro Discourse

2 Likes