Quick update. I wrote an extension that has an action that will create a window-level object that has the various utility functions. Seems to work OK (VERY limited testing) - I was able to execute commands from the console.
The only downside is you have to run the action in, say, a page load rule to make them available. Is there a place to put code in an extension that runs regardless of whether or not an action is called?
You can use a data element as well and just return a function or object as another option
// data element code
Have you looked at the new event type "Custom Code" that is available in the Core extension? Seems like just the thing for your needs.
It says "The code you provide in the editor will be run as soon as the library is loaded. Inside your code, call
trigger()whenever you would like the rule to fire."