Can't access a variable in browser with Javascript

Hey all, new to KM but fascinated by the possibilities.

I'm trying to use it to speed up some awkward development stuff, essentially trying to open the browser and execute some code that will paste a snippet inside the third-party textarea/code editor

If I simply paste the code into the browser javascript console, the code works fine. But when I try it using the macro, it fails to recognise the 'ace' editor. Is this because KM simply can't access variables in the browser? Is there a way to setup a macro to paste the code into the console instead?

here's a screenshot of my setup:
CleanShot 2022-06-30 at 10.33.40

And the errors:

I also tried this in Google Chrome with the same issues (apple events is enabled)

I assume as what you say is trying to open a browser window that runs a page containing ace editor. What happens is that the page is not fully loaded yet (hence , ace editor may not be initialized ) when Execute action is called, thus the code throws error. What you need to do is to add some delay to ensure that page is loaded. you can add a Pause action of few seconds before calling the Execute action.

I don't think that's the issue since the browser is already open and fully loaded before the script even starts.

Keyboard Maestro browser actions support Chrome and Safari (not Firefox, which lacks an osascript interface).

See the first 4 paragraphs of: actions:Browser Actions [Keyboard Maestro Wiki]

The first thing to check, before experimenting with an unsupported browser, is whether your actions work in the 2 supported browsers.

ComplexPoint,
Since he mentions that he has tried Chrome before and has the same issue,

I also tried this in Google Chrome with the same issues (apple events is enabled)

one possible explanation is that ace variable is not a global top-level variable as it could be defined using let or const, not var . let and constant variables (top-level or during debugging) can be accessed using browser console but not outside console.

And presumably we are not looking at the Chrome extension evaluation space when ace is found in the the console ?