diff --git a/examples/arguments.js b/examples/arguments.js
index 19ca8c02..06a777c8 100644
--- a/examples/arguments.js
+++ b/examples/arguments.js
@@ -1,8 +1,8 @@
if (phantom.arguments.length === 0) {
- phantom.log('Try to pass some arguments when invoking this script!');
+ console.log('Try to pass some arguments when invoking this script!');
} else {
phantom.arguments.forEach(function (arg, i) {
- phantom.log(i + ': ' + arg);
+ console.log(i + ': ' + arg);
});
}
phantom.exit();
diff --git a/examples/countdown.js b/examples/countdown.js
index c7b0e651..57dcd5ff 100644
--- a/examples/countdown.js
+++ b/examples/countdown.js
@@ -1,8 +1,8 @@
var t = 10;
while (t > 0) {
- phantom.log(t);
+ console.log(t);
phantom.sleep(1000);
t = t - 1;
}
-phantom.log('BLAST OFF');
+console.log('BLAST OFF');
phantom.exit();
diff --git a/examples/direction.js b/examples/direction.js
index b22df8e1..f5494979 100644
--- a/examples/direction.js
+++ b/examples/direction.js
@@ -3,8 +3,8 @@
if (phantom.storage.length === 0) {
var origin, dest;
if (phantom.arguments.length < 2) {
- phantom.log('Usage: direction.js origin destination');
- phantom.log('Example: direction.js "San Diego" "Palo Alto"');
+ console.log('Usage: direction.js origin destination');
+ console.log('Example: direction.js "San Diego" "Palo Alto"');
phantom.exit(1);
}
origin = phantom.arguments[0];
@@ -14,13 +14,13 @@ if (phantom.storage.length === 0) {
'&destination=' + dest + '&units=imperial&mode=driving&sensor=false'));
} else {
if (phantom.loadStatus === 'fail') {
- phantom.log('Unable to access network');
+ console.log('Unable to access network');
phantom.exit(1);
}
direction = x2j(phantom.content);
if (typeof direction == 'undefined') {
- phantom.log('No data available for ' + phantom.storage);
+ console.log('No data available for ' + phantom.storage);
phantom.exit(1);
}
@@ -30,11 +30,11 @@ if (phantom.storage.length === 0) {
ins = ins.replace(/\</ig, '<').replace(/\>/ig, '>');
ins = ins.replace(/\
/g, '');
- phantom.log(ins + ' (' + step.distance.text + ')');
+ console.log(ins + ' (' + step.distance.text + ')');
});
- phantom.log('');
- phantom.log(route.copyrights);
+ console.log('');
+ console.log(route.copyrights);
phantom.exit();
}
diff --git a/examples/fibo.js b/examples/fibo.js
index bc0445d6..aa5d7ea0 100644
--- a/examples/fibo.js
+++ b/examples/fibo.js
@@ -1,6 +1,6 @@
var fibs = [0, 1];
var ticker = window.setInterval(function () {
- phantom.log(fibs[fibs.length - 1]);
+ console.log(fibs[fibs.length - 1]);
fibs.push(fibs[fibs.length - 1] + fibs[fibs.length - 2]);
if (fibs.length > 10) {
window.clearInterval(ticker);
diff --git a/examples/hello.js b/examples/hello.js
index 57adcf9d..e273a974 100644
--- a/examples/hello.js
+++ b/examples/hello.js
@@ -1,2 +1,2 @@
-phantom.log('Hello, world!');
+console.log('Hello, world!');
phantom.exit();
diff --git a/examples/ipgeocode.js b/examples/ipgeocode.js
index 8d61fceb..aff5a209 100644
--- a/examples/ipgeocode.js
+++ b/examples/ipgeocode.js
@@ -4,8 +4,8 @@ cb = function (data) {
var loc = data.city;
if (data.region_name.length > 0)
loc = loc + ', ' + data.region_name;
- phantom.log('IP address: ' + data.ip);
- phantom.log('Estimated location: ' + loc);
+ console.log('IP address: ' + data.ip);
+ console.log('Estimated location: ' + loc);
phantom.exit();
};
diff --git a/examples/loadspeed.js b/examples/loadspeed.js
index c0eb687a..1ab1c394 100644
--- a/examples/loadspeed.js
+++ b/examples/loadspeed.js
@@ -1,20 +1,20 @@
if (phantom.storage.length === 0) {
if (phantom.arguments.length === 0) {
- phantom.log('Usage: loadspeed.js ');
+ console.log('Usage: loadspeed.js ');
phantom.exit();
} else {
var address = phantom.arguments[0];
phantom.storage = Date.now().toString();
- phantom.log('Loading ' + address);
+ console.log('Loading ' + address);
phantom.open(address);
}
} else {
var elapsed = Date.now() - new Date().setTime(phantom.storage);
if (phantom.loadStatus === 'success') {
- phantom.log('Page title is ' + document.title);
- phantom.log('Loading time ' + elapsed + ' msec');
+ console.log('Page title is ' + document.title);
+ console.log('Loading time ' + elapsed + ' msec');
} else {
- phantom.log('FAIL to load the address');
+ console.log('FAIL to load the address');
}
phantom.exit();
}
diff --git a/examples/movies.js b/examples/movies.js
index 8d0f8264..73c61a7e 100644
--- a/examples/movies.js
+++ b/examples/movies.js
@@ -4,7 +4,7 @@ var cbfunc = function (data) {
globaldata= data;
var list = data.query.results.movie;
list.forEach(function (item) {
- phantom.log(item.title + ' [' + item.rating.MPAA.content + ']');
+ console.log(item.title + ' [' + item.rating.MPAA.content + ']');
});
phantom.exit();
};
diff --git a/examples/pizza.js b/examples/pizza.js
index 09975dde..76705bbb 100644
--- a/examples/pizza.js
+++ b/examples/pizza.js
@@ -6,7 +6,7 @@ if (phantom.storage.length === 0) {
} else {
var list = document.querySelectorAll('div.bf');
for (var i in list) {
- phantom.log(list[i].innerText);
+ console.log(list[i].innerText);
}
phantom.exit();
}
diff --git a/examples/rasterize.js b/examples/rasterize.js
index 2bd40706..33760b9d 100644
--- a/examples/rasterize.js
+++ b/examples/rasterize.js
@@ -1,6 +1,6 @@
if (phantom.storage.length === 0) {
if (phantom.arguments.length !== 2) {
- phantom.log('Usage: rasterize.js URL filename');
+ console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
var address = phantom.arguments[0];
diff --git a/examples/run-jasmine.js b/examples/run-jasmine.js
index f5bdf4a0..2177a08a 100644
--- a/examples/run-jasmine.js
+++ b/examples/run-jasmine.js
@@ -1,6 +1,6 @@
if (phantom.storage.length === 0) {
if (phantom.arguments.length !== 1) {
- phantom.log('Usage: run-jasmine.js URL');
+ console.log('Usage: run-jasmine.js URL');
phantom.exit();
} else {
phantom.storage = 'run-jasmine';
@@ -10,14 +10,14 @@ if (phantom.storage.length === 0) {
window.setInterval(function () {
var list, el, desc, i, j;
if (document.body.querySelector('.finished_at')) {
- phantom.log(document.body.querySelector('.description').innerText);
+ console.log(document.body.querySelector('.description').innerText);
list = document.body.querySelectorAll('div.jasmine_reporter > div.suite.failed');
for (i = 0; i < list.length; ++i) {
el = list[i];
desc = el.querySelectorAll('.description');
- phantom.log('');
+ console.log('');
for (j = 0; j < desc.length; ++j) {
- phantom.log(desc[j].innerText);
+ console.log(desc[j].innerText);
}
}
phantom.exit();
diff --git a/examples/seasonfood.js b/examples/seasonfood.js
index fe875f12..f827d461 100644
--- a/examples/seasonfood.js
+++ b/examples/seasonfood.js
@@ -7,7 +7,7 @@ var cbfunc = function (data) {
'July', 'August', 'September',
'October', 'November', 'December'];
list.forEach(function (item) {
- phantom.log([item.name.replace(/\s/ig, ' '), ':',
+ console.log([item.name.replace(/\s/ig, ' '), ':',
names[item.atItsBestUntil], 'to',
names[item.atItsBestFrom]].join(' '));
});
diff --git a/examples/tweets.js b/examples/tweets.js
index dd6a6c74..daa8ec29 100644
--- a/examples/tweets.js
+++ b/examples/tweets.js
@@ -6,7 +6,7 @@ if (phantom.storage.length === 0) {
} else {
var list = document.querySelectorAll('span.status');
for (var i = 0; i < list.length; ++i) {
- phantom.log((i + 1) + ': ' + list[i].innerHTML.replace(/<.*?>/g, ''));
+ console.log((i + 1) + ': ' + list[i].innerHTML.replace(/<.*?>/g, ''));
}
phantom.exit();
}
diff --git a/examples/useragent.js b/examples/useragent.js
index 604f7a12..46b69ac5 100644
--- a/examples/useragent.js
+++ b/examples/useragent.js
@@ -3,6 +3,6 @@ if (phantom.storage.length === 0) {
phantom.userAgent = 'SpecialAgent';
phantom.open('http://www.httpuseragent.org');
} else {
- phantom.log(document.getElementById('myagent').innerText);
+ console.log(document.getElementById('myagent').innerText);
phantom.exit();
}
diff --git a/examples/weather.js b/examples/weather.js
index 72a9a08d..4e546c2b 100644
--- a/examples/weather.js
+++ b/examples/weather.js
@@ -4,17 +4,17 @@ if (phantom.storage.length === 0) {
city = phantom.arguments.join(' ');
}
phantom.storage = city;
- phantom.log('Loading ' + city);
+ console.log('Loading ' + city);
phantom.open(encodeURI('http://www.google.com/ig/api?weather=' + city));
} else {
if (phantom.loadStatus === 'fail') {
- phantom.log('Unable to access network');
+ console.log('Unable to access network');
phantom.exit(1);
}
if (document.querySelectorAll('problem_cause').length > 0) {
- phantom.log('No data available for ' + phantom.storage);
+ console.log('No data available for ' + phantom.storage);
phantom.exit(1);
}
@@ -23,18 +23,18 @@ if (phantom.storage.length === 0) {
return e.querySelector(s).attributes.data.value;
};
- phantom.log('');
- phantom.log('City: ' + data('weather > forecast_information > city'));
- phantom.log('Current condition: ' + data('weather > current_conditions > condition'));
- phantom.log('Temperature: ' + data('weather > current_conditions > temp_f') + ' F');
- phantom.log(data('weather > current_conditions > humidity'));
- phantom.log(data('weather > current_conditions > wind_condition'));
- phantom.log('');
+ console.log('');
+ console.log('City: ' + data('weather > forecast_information > city'));
+ console.log('Current condition: ' + data('weather > current_conditions > condition'));
+ console.log('Temperature: ' + data('weather > current_conditions > temp_f') + ' F');
+ console.log(data('weather > current_conditions > humidity'));
+ console.log(data('weather > current_conditions > wind_condition'));
+ console.log('');
var forecasts = document.querySelectorAll('weather > forecast_conditions');
for (var i = 0; i < forecasts.length; ++i) {
var f = forecasts[i];
- phantom.log(data('day_of_week', f) + ': ' +
+ console.log(data('day_of_week', f) + ': ' +
data('low', f) + '-' + data('high', f) + ' F ' +
data('condition', f));
}
diff --git a/src/phantomjs.cpp b/src/phantomjs.cpp
index 8fcc2452..2e2c6209 100644
--- a/src/phantomjs.cpp
+++ b/src/phantomjs.cpp
@@ -45,6 +45,7 @@ public slots:
bool shouldInterruptJavaScript();
protected:
+ void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID);
QString userAgentForUrl(const QUrl &url) const;
private:
@@ -58,6 +59,13 @@ WebPage::WebPage(QObject *parent)
m_userAgent = QWebPage::userAgentForUrl(QUrl());
}
+void WebPage::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID)
+{
+ if (!sourceID.isEmpty())
+ std::cout << qPrintable(sourceID) << ":" << lineNumber << " ";
+ std::cout << qPrintable(message) << std::endl;
+}
+
bool WebPage::shouldInterruptJavaScript()
{
QApplication::processEvents(QEventLoop::AllEvents, 42);
@@ -104,7 +112,6 @@ public:
public slots:
void exit(int code = 0);
- void log(const QString &msg);
void open(const QString &address);
bool render(const QString &fileName);
void sleep(int ms);
@@ -204,11 +211,6 @@ QString Phantom::loadStatus() const
return m_loadStatus;
}
-void Phantom::log(const QString &msg)
-{
- std::cout << qPrintable(msg) << std::endl;
-}
-
void Phantom::open(const QString &address)
{
m_page.triggerAction(QWebPage::Stop);