google chrome extension :: console.log() from background page?

后端 未结 11 1961

If I call console.log(\'something\'); from the popup page, or any script included off that it works fine.

However as the background page is not directly

11条回答
  •  执笔经年
    2020-11-30 17:47

    In relation to the original question I'd like to add to the accepted answer by Mohamed Mansour that there is also a way to make this work the other way around:

    You can access other extension pages (i.e. options page, popup page) from within the background page/script with the chrome.extension.getViews() call. As described here.

     // overwrite the console object with the right one.
    var optionsPage = (  chrome.extension.getViews()  
                     &&  (chrome.extension.getViews().length > 1)  ) 
                    ? chrome.extension.getViews()[1] : null;
    
     // safety precaution.
    if (optionsPage) {
      var console = optionsPage.console;
    }
    

提交回复
热议问题