12

I am developing chrome extension, and the thing that i really need is to get console output as object.

Is it possible to get any of that in chrome extension popup.html/popup.js or somewhere ?

I have tab object, can i get somehow that particular tabs console, or error output from the inspector/devtool in chrome console as object in code?

afuzzyllama
  • 6,538
  • 5
  • 47
  • 64
XFaktor
  • 167
  • 1
  • 2
  • 12
  • do you mean that you want to catch any errors that would go out to the console and then print them to the screen? – Ryan Oct 22 '12 at 17:41
  • When i press extension button (same as when i open extension popup.html / popup.js) i want to get full console output, and do manipulations with it, count errors, count warning, parse in some way output and then display it in the popup html. – XFaktor Oct 22 '12 at 17:44
  • But nevertheless it does not mater what and how i will do it, since i am myself not sure, but first i need to get the output/console/logs/error or whatever we should call it as object in code :) p.s. thanks for trying to help :) – XFaktor Oct 22 '12 at 17:46
  • This must be possible by now, right? – Ryan Dec 17 '19 at 17:34

4 Answers4

10

Google Chrome Console has no possibility (upon now) to get the Output/Contents of the Console.

tobspr
  • 8,200
  • 5
  • 33
  • 46
  • The `console` object does not have `dump()` on its prototype. – Alexander Pavlov Oct 22 '12 at 15:50
  • Uncaught TypeError: Object # has no method 'dump' – XFaktor Oct 22 '12 at 15:57
  • So it seems it was just a beta comand or its just available from web pages. – tobspr Oct 22 '12 at 15:59
  • I am not sure, but tried this one in all scopes of code, does not seem to work. Thanks for answer nevertheless. – XFaktor Oct 22 '12 at 17:43
  • If you run console.log(console.__proto__), you see the console object has no function for this. – tobspr Oct 22 '12 at 17:48
  • I agree but it is not console that should have this function it is google chrome api or extensions api/function , like : http://developer.chrome.com/extensions/devtools.inspectedWindow.html that would allow to get content from console. It is not console that should do something :) – XFaktor Oct 22 '12 at 17:50
  • Yes, but why do you need the console output? It is usually just for debugging ... – tobspr Oct 22 '12 at 17:51
  • I am creating extension, that should parse / validate and etc and etc the page, so i wanted to get the console output, to be able to count errors in there or to display them for standard user in the human way :) – XFaktor Oct 22 '12 at 17:53
  • ahh :) of course, but i just thought maybe it is possible, since it by itself was extension in the beginning just the one that is built in. It is just weird because chrome itself uses these errors and output in many places, and it is weird that it can not be got in extension :) Nevertheless thanks for conversation :) – XFaktor Oct 22 '12 at 17:58
0

In your popup.js file you can just use console.log("stuff") then right click on your extension and go to the debugger or inspect_element -> console, to see the output.

From your background file you will need to do:

popup = chrome.extension.getViews('popup'); // this returns an array

popup[0].console.log("stuff");

Then simply do the same steps as above.

See: api get views for more on interaction between views and here for: another way to interact between pages.

Ryan
  • 5,644
  • 3
  • 38
  • 66
  • Completely not what i wanted :) but thanks nevertheless. What i need is to get the output in the code as object or string, not just to see it by myself :) thanks – XFaktor Oct 22 '12 at 17:28
  • if you console.log(tab) and tab is an object it will show you everything that is contained in that object. if your tab object has an attribute tab.error and you console.log(tab.error) then it will show you the error. Other wise I don't know what your getting at, cause everything is an object in javascript. – Ryan Oct 22 '12 at 17:35
  • javascript is not a 'typed' language. When you declare a var then your really declaring an object, no matter what you put in it. – Ryan Oct 22 '12 at 17:37
  • console.log(tab) does not have any object accordingly to console, console is a additional devtool in chrome api, i need somehow to talk to that devtool and get it output as object for current tab. It does not have tab.error object. – XFaktor Oct 22 '12 at 17:38
  • Thanks for clarifying. But the my misleading explanation between objects and output, does not effect the question and that i need to get console output object for particular tab in code. – XFaktor Oct 22 '12 at 17:41
0

There appears to be a way to get console output in an extension, though it requires launching Chrome with a special flag and giving the extension extra file reading permissions.

  1. This SO Answer shows how you can have all of Chrome's actions, including console.log() strings, saved in a local file, by launching Chrome with --enable-logging --v=1
  2. Then this SO Answer shows how an extension can read that local file.
Stan James
  • 2,535
  • 1
  • 28
  • 35
-3

There are three JavaScript context in Chrome Extemsion : Content Script, Backgrond Script and Popup. In each context of code you can use console.log(). i.e console.log("I am here");

var tempObject = {'one': 'v_one', 'two', 'v_two'};

console.log(tempObject);

Note: Output will be available only in which context of code you mentioned console.log('Hello');

Raghvendra Parashar
  • 3,883
  • 1
  • 23
  • 36