I am trying a PhantomJS script in ClojureScript. I am targeting Node and using phantomjs-node [1]. I have a basic working example :
(def phantom (js/require "phantom"))
(defn -main [& args]
(-> phantom
(.create (fn [browser]
(-> browser
(.createPage (fn [page]
(-> page
(.open "http://google.com" (fn [status]
(if (= status "success")
(-> page (.render "example.png")))
(-> browser .exit)))))))))))
Now, if I use the evaluatefunction [2] of the PhantomJS webpage object, I get the following error:
phantom stdout: ReferenceError: Can't find variable: <namespace here>
When compiled in JavaScript, the code to be evaluated contains the CLJS namespace and therefore does not display correctly in the context of the PhantomJS webpage object. Here is an example:
(defn -main [& args]
(-> phantom
(.create (fn [browser]
(-> browser
(.createPage (fn [page]
(-> page
(.open "http://google.com" (fn [status]
(println (str "opened google? " status))
(-> page
(.evaluate
(println (str "Page title is " %))
(-> browser .exit))))))))))))))
How can I prevent code from being evaluated in a PhantomJS webpage object from a namespace with a CLJS namespace? Or, secondly, do I have other options?