[Solved] Execute JavaScript in Safari sometimes fails

I use this action daily, but sometimes, and I can’t find what could be the issue, it fails to execute.

It doesn’t matter if quit everything or restart the machine it simply wont work. I always have to go to another mac for it to work again.

What bugs me is what seems to be a 24h countdown for it to start working again on the failed machine.

Does it all make any sense?

Thank you.

There may be cases in which the code is raising an exception, in which case you should be able to see the problem line in the debugging panel of the Safari web inspector for the affected page.

https://developer.apple.com/library/prerelease/mac/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/GettingStarted/GettingStarted.html#//apple_ref/doc/uid/TP40007874-CH2-SW2

Thank you for the reply. Found nothing on the debugging panel. However I think a have traced the problem with an infrequently used macro with some javascripts on it. I’ve changed how KM executes the javascript on the page and it has hanged on me now, requiring a relaunch of the engine. Is there a KM bug/console report file I could review?

Found the offending action: Set Safari Field document.forms["mainRegForm"]["html"] to %Variable%PageSource%

KM Engine hangs at this point.

PageSource is acquired by this script: window.document.documentElement.outerHTML using "Execute Javascript in Safari" action, saving the results to PageSource variable.

Does this cast any light on the problem? Why KM engine hangs and why Javascript actions no longer work even after reboot?

As I said, the problem seems to resolve itself after a 24h period.

On Console I'm getting this message: "Keyboard Maestro[577]: Keyboard Maestro: Ignoring NSRunningApplication with pid -1" repeatedly

See image below:

So I got this, this morning:

Deleted the content of the variables and KM Javascrpit actions work again.

Peter, what could be the issue so I can workaround perhaps?

Thank you.

Hey There,

Keyboard Maestro is set to not eat too much of your environment memory.

Make sure you zero-out large variables after using them.

You may have all kinds of junk in variables left over from scripts. Delete those in the variable pane of the Keyboard Maestro prefs.

What are you doing with the text?

I send mine to BBEdit with AppleScript and don't fool with Keyboard Maestro variables.

-Chris

Thanks Chris.

I moved some things around and trashed some old stuff I had on KM and it’s all good now. Yes, the problem was having several variables hosting a big clipboard.

I updated some macros to save large texts to clipboards instead of variables and made sure I wasn’t reusing the same variables on different macros.

Thanks for the help.