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

走远了吗. 提交于 2019-12-05 17:12:22

问题


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?


回答1:


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




回答2:


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.




回答3:


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.



回答4:


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



来源:https://stackoverflow.com/questions/13013535/google-chrome-extension-is-it-possible-to-get-console-output-js-errors-conso

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!