mirror of
https://github.com/encounter/phantomjs.git
synced 2026-03-30 11:35:11 -07:00
a313d1befd
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
41 lines
1.4 KiB
JavaScript
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;
|
|
}
|