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