Ariya Hidayat 2011-08-20 17:56:18 -07:00
parent 149c951262
commit 319fd80ec3
5 changed files with 29 additions and 0 deletions

View File

@ -15,6 +15,7 @@ Version 1.3.0
New features
* Presistent cookie support using --cookies=cookies.ini
* Added callback for page initialization (issue 143)
Examples

24
examples/unrandomize.js Normal file
View File

@ -0,0 +1,24 @@
// Modify global object at the page initialization.
// In this example, effectively Math.random() always returns 0.42.
var page = new WebPage();
page.onInitialized = function () {
page.evaluate(function () {
Math.random = function() {
return 42 / 100;
};
});
};
page.open('http://ariya.github.com/js/random/', function (status) {
var result;
if (status !== 'success') {
console.log('Network error.');
} else {
console.log(page.evaluate(function () {
return document.getElementById('numbers').textContent;
}));
}
phantom.exit();
});

View File

@ -19,6 +19,8 @@ window.WebPage = function() {
// deep copy
page.settings = JSON.parse(JSON.stringify(phantom.defaultPageSettings));
defineSetter("onInitialized", "initialized");
defineSetter("onLoadStarted", "loadStarted");
defineSetter("onLoadFinished", "loadFinished");

View File

@ -104,6 +104,7 @@ WebPage::WebPage(QObject *parent)
m_webPage = new CustomPage(this);
m_mainFrame = m_webPage->mainFrame();
connect(m_mainFrame, SIGNAL(javaScriptWindowObjectCleared()), SIGNAL(initialized()));
connect(m_webPage, SIGNAL(loadStarted()), SIGNAL(loadStarted()));
connect(m_webPage, SIGNAL(loadFinished(bool)), SLOT(finish(bool)));

View File

@ -86,6 +86,7 @@ public slots:
void mouseMoveTo(int x, int y);
signals:
void initialized();
void loadStarted();
void loadFinished(const QString &status);
void javaScriptAlertSent(const QString &msg);