1 # Use 'page.injectJs()' to load the script itself in the Page context
4 page = require('webpage').create()
6 # Route "console.log()" calls from within the Page context to the main
7 # Phantom context (i.e. current "this")
8 page.onConsoleMessage = (msg) -> console.log(msg)
10 page.onAlert = (msg) -> console.log(msg)
12 console.log "* Script running in the Phantom context."
13 console.log "* Script will 'inject' itself in a page..."
14 page.open "about:blank", (status) ->
15 if status is "success"
16 if page.injectJs("injectme.coffee")
17 console.log "... done injecting itself!"
19 console.log "... fail! Check the $PWD?!"
22 alert "* Script running in the Page context."