I'm creating a custom Chrome extension, which is going to retrieve data about an active tab before sending it to a secondary website.
I've been trying to find a method on how to retrieve the console output for an active tab. chrome.tabs.getSelected
seemed promising at first, however, it doesn't offer an output of the console text. I've been digging for couple of hours without much success of finding a method that could give me this info.
Could anyone point me in the right direction please?
Edit:
As a way to keep track of everything I've tried so far, for myself and others, I will add info below.
I've found a possible solution which may work for me. The below code will extend the console methods log, error and warn. I'm currently researching for a method that maybe able to attach this code to the active tab, so I can collect the console outputs in the arrays and then make these available on my extension to be sent over to the secondary website.
I will post more info as I progress through it.
var logs = [],
cLogs = [],
cErrors = [],
cWarns = [],
_log = console.log,
_error = console.error,
_warn = console.warn;
console.log = function () {
for (var i = 0; i < arguments.length; i++) {
logs.push(arguments[i]);
cLogs.push(arguments[i]);
}
_log.apply(this, arguments);
};
console.error = function () {
for (var i = 0; i < arguments.length; i++) {
logs.push(arguments[i]);
cErrors.push(arguments[i]);
}
_error.apply(this, arguments);
};
console.warn = function () {
for (var i = 0; i < arguments.length; i++) {
logs.push(arguments[i]);
cWarns.push(arguments[i]);
}
_warn.apply(this, arguments);
};
console.log('welcome');
console.error({'foobar': ['foo','bar']});
console.warn({'foo':'bar'});
_log(logs);