rewrite this whole thing as a node script to avoid CSP problems