Files
phantomjs/python/bootstrap.js
T
IceArmy 841dc41f41 Introduce 'onLoadStarted' event which will fire upon page loads.
An example use:

var page = new WebPage();
      page.onLoadStarted = function() {
          console.log('start loading...Please wait');
      };
      page.open("http://example.com", function (status) {
          console.log('Done ' + status);
          phantom.exit();
      });
2011-06-06 14:15:08 -07:00

54 lines
1.8 KiB
JavaScript

// This allows creating a new web page using the construct "new WebPage",
// which feels more natural than "phantom.createWebPage()".
window.WebPage = function() {
var page = phantom.createWebPage();
// deep copy
page.settings = JSON.parse(JSON.stringify(phantom.defaultPageSettings));
// private, don't touch this
page.handlers = {};
page.__defineSetter__("onLoadStarted", function(f) {
if (this.handlers && typeof this.handlers.loadStarted === 'function') {
try {
this.loadStarted.disconnect(this.handlers.loadStarted);
} catch (e) {}
}
this.handlers.loadStarted = f;
this.loadStarted.connect(this.handlers.loadStarted);
});
page.onAlert = function (msg) {};
page.onConsoleMessage = function (msg) {};
page.open = function () {
if (typeof this.onAlert === 'function') {
this.javaScriptAlertSent.connect(this.onAlert);
}
if (typeof this.onConsoleMessage === 'function') {
this.javaScriptConsoleMessageSent.connect(this.onConsoleMessage);
}
if (arguments.length === 2) {
this.loadStatusChanged.connect(arguments[1]);
this.openUrl(arguments[0], 'get', this.settings);
return;
} else if (arguments.length === 3) {
this.loadStatusChanged.connect(arguments[2]);
this.openUrl(arguments[0], arguments[1], this.settings);
return;
} else if (arguments.length === 4) {
this.loadStatusChanged.connect(arguments[3]);
this.openUrl(arguments[0], {
operation: arguments[1],
data: arguments[2]
}, this.settings);
return;
}
throw "Wrong use of WebPage#open";
};
return page;
}