Javascript that works in Safari console returning empty in Keyboard Maestro

I've been using a macro that scrapes a webpage for months, and it has suddenly stopped working. An "Execute Javascript in Safari" action is supposed to set a variable, but the variable is always empty. The javascript works fine in Safari console.

Example Site

JavaScript:

document.getElementsByClassName("date-and-name")[0].innerText.trim();

When I navigate to the above example site, wait for the site to finish loading, and run the macro below, a notification with "%date%" displays, when it should show the date.

Figured it out.

I needed to enable "Allow JavaScript from Apple Events" in Safari again.

You many need to double-check your Safari settings. Both Safari and Chrome have made recent updates that can disable JavaScript in Browser.

See:

1 Like

Thanks JMichaelTX, that was exactly the problem.

1 Like