1 // Use 'page.injectJs()' to load the script itself in the Page context
3 if ( typeof(phantom) !== "undefined" ) {
4 var page = require('webpage').create();
6 // Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
7 page.onConsoleMessage = function(msg) {
11 page.onAlert = function(msg) {
15 console.log("* Script running in the Phantom context.");
16 console.log("* Script will 'inject' itself in a page...");
17 page.open("about:blank", function(status) {
18 if ( status === "success" ) {
19 console.log(page.injectJs("injectme.js") ? "... done injecting itself!" : "... fail! Check the $PWD?!");
24 alert("* Script running in the Page context.");