When editing a macro, the FrontBrowserJavaScripttoken continues to evaluate regardless of whether the action that contains it is disabled or if Evaluate Condition Results (in the View menu) is off.
The only way to stop the evaluation is to stop editing the macro.
Steps to Reproduce
Add a Set Variable action (it could probably be a few different actions).
In the to field, insert the FrontBrowserJavaScript token.
Using the default script is enough: %FrontBrowserJavaScript%document.forms[0].innerHTML%
(I'm currently using KM 11.0.3. But I originally found this in KM 10.)
Results
Go to your Front Browser, open the Inspector, go to the Console and watch the errors stream in and accumulate: TypeError: undefined is not an object (evaluating 'document.forms[0].innerHTML')
The TypeError is expected. The screenshot is showing how they're repeating (1 + 18 times in this case) as long as the macro is being edited.
Additionally:
I've found the same results via Safari, Chrome, and Brave (to be expected) and via the sibling tokens SafariJavaScript and ChromeJavaScript.
The performance of the system and Keyboard Maestro is degraded a little because the evaluation takes up CPU cycles (in my case that's a ~1-2% increase to KM and the KM Engine). But this is a known consequence of Evaluating Conditions:
There should be some way to stop the repeated evaluation when using this token and editing a macro.
The most obvious (to me) and intuitive way would be that disabling the action would pause evaluation.
But I can also imagine it respecting the state of the Evaluate Condition ResultsView menu item.
I also thought about whether a UI element (like: (Click for result) in the If action) would help. But I assume that would be tricky because it would have to be placed in every action that could possibly use the FrontBrowserJavaScript token. And that sounds like a nightmare for a few different reasons.
Are you proposing a change to the KM Editor's behaviour?
I can see why the current behaviour is undesirable for you, and I can see you have some workaround ideas, but what would you consider to be the ideal behaviour for the KM Editor? Do you think perhaps there should be a new menu item on each actions cogwheel to override the global evaluation flag? That might be a solution.
While the manual page for Tokens correctly states that "Tokens in Keyboard Maestro represent placeholders, that you enter during design time, for information that will be replaced in the text at run time", it does not state whether KM will keep polling for that information. On the face of it, there is no reason why it should, but I do wonder if there is a design decision here (perhaps affecting all tokens?) rather than a bug. I look forward to finding out!
There should be some way to stop the repeated evaluation while editing a macro that has an action that contains this token. Without this options there's:
A noticeable performance hit.
The browser's console accumulates whatever is output and can make it hard to distinguish the signal from the noise.
If the JS is performing some kind of interaction that changes the page's state (ex: Clicking a button), that will keep happening over and over again as you're editing the macro.
The only way around this, while editing, is to delete the action containing the FrontBrowserJavaScript token.
Agreed. That would be one way to do it.
Although that still runs into the issue I mentioned where it might be very difficult to add that option to all of the actions that could possible accept the FrontBrowserJavaScript token. But I don't know.
At least it wouldn't require the same kind of UI considerations as adding something like the (Click for result) button that the If action has.
Agreed.
In this case, it does keep polling.
I wonder what other tokens behave similarly.
Well there are definitely times where I can appreciate the repeated evaluation while I'm working on that specific action. It's when I'm editing the other actions that it gets in the way.
Fair enough. I was simply suggesting a universal toggle because it seemed like the simplest quick fix. There may be other approaches. For example, there could be a new tab in the KM Editor Configuration that would list all 200 tokens (or just a few of them that really need this feature), each with a checkbox to allow users to disable that specific token from being evaluated in the editor. I don't think that's a better idea, but it's a valid idea.
That's an interesting idea. There are pros/cons to the global (this idea) vs. specific (per/action) approach.
I don't want to be too prescriptive about the implementation since there's a lot I don't know re: the considerations @peternlewis has to take into account.