How to execute Javascript in Chrome website

Hello and Happy New Year to my fellow Keyboard Maestros.

I’ve got a question. Basically using KM 11.0.4 on a fully updated Google Chrome install and Mac OS Tahoe 26.1 I can’t run Javascript at all. Yes, I have “Allow Javascript from Apple Events” turned on, and yes, I’ve got full permission for automation etc. for both Keyboard Maestro and Keyboard Maestro Engine. I can’t talk to the browser to get information on the currently loaded webpage at all.

Have you displayed the reported error, or looked at the Engine.log?

Does the Security preference setting indicate an issue with web browser control for Chrome?

Hi, I can’t see any error, just nothing happens. Checking the log, I see lines like

2026-01-05 14:20:54 Execute macro “Open Applescript” from trigger The Hot Key ⌃⌥A is pressed
2026-01-05 14:20:55 Execute macro “Open Maestro” from trigger The Hot Key ⌃Q is pressed
2026-01-05 14:20:58 Execute macro “Test Download from Nozomi” from trigger Editor

The bottom is this test script. Is there a way to get more info on the execution?

For the Mac OS security, all settings are active, I think. Automation, permission to view screen, permission to access all disks, etc. I do a lot of automation so these things are always being used.

It’s just impossible to get any javascript to execute and return information to me.

You are not using the modern syntax.

See the Help for the action.

Specifically: “you need to return values to the action using the return syntax”.

return document.title

Thanks, that worked for me! So I am apparently bad at Javascript :slight_smile:

Keyboard Maestro has a nice library of built-in tokens to streamline your workflows. For instance, you can instantly get the title of your active browser tab using the %FrontBrowserTitle% token.

You can even execute JavaScript directly with a token by placing your code between the percent signs: %FrontBrowserJavaScript%YOUR_CODE_HERE%

For example, you can use this token in any text field that accepts KM tokens:
%FrontBrowserJavaScript%document.title%

WARNING: Use this token mindfully. While an action containing this token is expanded in the Keyboard Maestro editor, the JavaScript may execute continuously (the preview in the red rectangle is updated constantly). To prevent unnecessary CPU usage or disrupting your browser, collapse the action once you have finished configuring it.

1 Like

There's also....

1 Like