2011-06-29 03:34:01 +04:00
|
|
|
# Use 'page.injectJs()' to load the script itself in the Page context
|
2011-06-17 11:04:08 +04:00
|
|
|
|
|
|
|
if phantom?
|
2011-09-13 00:17:54 +04:00
|
|
|
page = require('webpage').create()
|
2011-06-17 11:04:08 +04:00
|
|
|
|
|
|
|
# Route "console.log()" calls from within the Page context to the main
|
|
|
|
# Phantom context (i.e. current "this")
|
|
|
|
page.onConsoleMessage = (msg) -> console.log(msg)
|
|
|
|
|
|
|
|
page.onAlert = (msg) -> console.log(msg)
|
|
|
|
|
|
|
|
console.log "* Script running in the Phantom context."
|
|
|
|
console.log "* Script will 'inject' itself in a page..."
|
|
|
|
page.open "about:blank", (status) ->
|
|
|
|
if status is "success"
|
2011-09-14 01:50:12 +04:00
|
|
|
if page.injectJs("injectme.coffee")
|
2011-06-17 11:04:08 +04:00
|
|
|
console.log "... done injecting itself!"
|
|
|
|
else
|
|
|
|
console.log "... fail! Check the $PWD?!"
|
|
|
|
phantom.exit()
|
|
|
|
else
|
|
|
|
alert "* Script running in the Page context."
|
|
|
|
|