Pants. Serializing the action stack is going to be tricky, since it's a pile of functions (and closures).
One fix is to write a language - based on lox or mal - and have the ui save instructions in those terms.
let r = rectangle(10, 10, 35, 60)
set r lineWidth 2
set r strokeStyle "green"
draw r
// useful for humans, not sure if would ever be generated
set globalStyle {lineWidth: 4, strokeStyle: "brown" }
for (let r = 10; r <= 50; r += 10)
let c = circle(25, 25, r)
draw c
done
I don't think we need a full on VM, but a parser to build an ast, and then a visitor to execute - jlox, but in JavaScript and maybe a little stripped down (but also with object literals).
Worth a try, I haven't been through jlox in a while.