最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google chrome extension : is it possible to get console output (js errors, console.log or etc) - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share Improve this question edited Oct 22, 2012 at 17:52 afuzzyllama 6,5485 gold badges49 silver badges64 bronze badges asked Oct 22, 2012 at 14:27 XFaktorXFaktor 1671 gold badge2 silver badges12 bronze badges 4
  • 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 Commented Oct 22, 2012 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 Commented Oct 22, 2012 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 Commented Oct 22, 2012 at 17:46
  • This must be possible by now, right? – Ryan Commented Dec 17, 2019 at 17:34
Add a ment  | 

4 Answers 4

Reset to default 10

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

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.

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.

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');

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论