mirror of https://github.com/vitalif/phantomjs
parent
149c951262
commit
319fd80ec3
|
@ -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
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
|
@ -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");
|
||||
|
|
|
@ -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)));
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue