Files
phantomjs/python/bootstrap.js
T
IceArmy a313d1befd PyPhantomJS version 1.2.0
Refactored most of functionalities to WebPage object
WebPage object can have settings
Support different HTTP operations for loading a page
Simplify buffer handling in render()
Refactor render(), split the buffer rendering to its own function
Render the web page using the tiling approach
WebPage callback for it's console message
Make exit() synchronous
WebPage callback for its JS alert
Updated all examples
2011-05-31 16:23:06 -07:00

41 lines
1.4 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));
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;
}