2012-05-12 04:32:16 +04:00
|
|
|
p = require("webpage").create()
|
2012-12-07 00:29:37 +04:00
|
|
|
|
2012-05-12 04:32:16 +04:00
|
|
|
p.onConsoleMessage = (msg) ->
|
|
|
|
console.log msg
|
|
|
|
|
2012-12-07 00:29:37 +04:00
|
|
|
# Calls to "callPhantom" within the page 'p' arrive here
|
2012-05-12 04:32:16 +04:00
|
|
|
p.onCallback = (msg) ->
|
|
|
|
console.log "Received by the 'phantom' main context: " + msg
|
|
|
|
"Hello there, I'm coming to you from the 'phantom' context instead"
|
|
|
|
|
|
|
|
p.evaluate ->
|
2012-12-07 00:29:37 +04:00
|
|
|
# Return-value of the "onCallback" handler arrive here
|
|
|
|
callbackResponse = window.callPhantom "Hello, I'm coming to you from the 'page' context"
|
2012-05-12 04:32:16 +04:00
|
|
|
console.log "Received by the 'page' context: " + callbackResponse
|
|
|
|
|
|
|
|
phantom.exit()
|