I'm making a debugging tool, part of it is a Chrome Extension, that is supposed to capture console.log calls and send the output through WebSocket.
How can I wrap console.log in content page so that it sends messages to background script? Following doesn't work:
function requestContent() {
var code = [
"var __console_log = window.console.log;",
"function __sendSublime(msg) {",
"chrome.extension.sendRequest(null, {",
"method: 'send',",
"data: msg",
"});",
"__console_log(msg);",
"}",
"window.console.log = __sendSublime;"].join('');
chrome.tabs.executeScript(null, {code: code});
}
I'm calling this function from background script.