ConsoleAgent forwards all console message from the remote console to the local console.
Log a remote message to the local console
function _log(message) {
var level = message.level;
if (level === "warning") {
level = "warn";
}
var text = "ConsoleAgent: " + message.text;
if (message.url) {
text += " (url: " + message.url + ")";
}
if (message.stackTrace) {
var callFrame = message.stackTrace[0];
text += " in " + callFrame.functionName + ":" + callFrame.columnNumber;
}
console[level](text);
}
// WebInspector Event: Console.messageAdded
function _onMessageAdded(event, res) {
// res = {message}
_lastMessage = res.message;
_log(_lastMessage);
}
// WebInspector Event: Console.messageRepeatCountUpdated
function _onMessageRepeatCountUpdated(event, res) {
// res = {count}
if (_lastMessage) {
_log(_lastMessage);
}
}
// WebInspector Event: Console.messagesCleared
function _onMessagesCleared(event, res) {
// res = {}
}
Enable the inspector Console domain
function enable() {
return Inspector.Console.enable();
}