I've got a bit stuck with this so hopefully someone can point me in the right direction.
Basically I'm trying to execute a javascript in Chrome for a specific website.
The javascript works in Safari - from the Safari Dev Console, from the execute JS command in KM and also from Applescript Script Editor.
The same javascript works in Chrome from the Dev Console, but does NOT work from KM or from Script Editor.
Below is the Applescript code for bith Safari and Chrome. In Script Editor when targetting Chrome it just says "missing value", so unsurprisingly in KM it also doesn't do anything. The JS is meant to adda an item to the basket
Both require the following webpage to be open and the active tab:
tell application "Safari"
activate
set theJS to "Ecwid.Cart.addProduct({id: 616681326, quantity: 1, options: {'Print Size':'A4 297x210mm'},});"
tell front document
do JavaScript theJS
end tell
end tell
tell application "Google Chrome"
activate
set theJS to "Ecwid.Cart.addProduct({id: 616681326, quantity: 1, options: {'Print Size':'A4 297x210mm'},});"
execute front window's active tab javascript theJS
end tell
Other JS commands are working in Chrome from from KM or Script Editor so it doesn't appear to be a general issue with executing standard JS commands from KM or Script Editor
The actual javascript being executed is a site specific API Javascript function - not sure if that makes any difference when dealing with Chrome?
If anyone has any insight it would be so appreciated.
OP's issue was that a particular JavaScript worked in Safari, from the console or a KM macro, worked in the Chrome console, but didn't work in Chrome using a KM macro.
Is your issue that specific, or something else? Can you supply a macro or some JS that will demonstrate the problem? Do any "Execute JavaScript in..." actions targeting that browser work? Have they ever worked (Chromium's AppleScript support, required for the action, comes and goes with various updates)?
I never did get it to work in chrome, or work out why (JS and developer tools not my speciality at all).
My workaround for chrome was to get KM to open the Console, paste in the javascript, run it and then close the console. Not pretty, but works just fine.
@peternlewis Is there a way to analyse the JavaScript before it was minified to see if there are something, which gets processed by KM before it gets to Google Chrome?
Incidentally, for a script like that which makes no use of Keyboard Maestro variables, you can get the best security and performance by choosing Include No Variables: