Monday, June 3, 2024
46
rated 0 times [  52] [ 6]  / answers: 1 / hits: 193288  / 14 Years ago, thu, september 30, 2010, 12:00:00

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 run off the popup page it is not included in the console.



Is there a way that I can get console.log()'s in the background page to show up in the console for the popup page?



is there any way to, from the background page call a function in the popup page?


More From » google-chrome

 Answers
39

Any extension page (except content scripts) has direct access to the background page via chrome.extension.getBackgroundPage().



That means, within the popup page, you can just do:



chrome.extension.getBackgroundPage().console.log('foo');


To make it easier to use:



var bkg = chrome.extension.getBackgroundPage();
bkg.console.log('foo');


Now if you want to do the same within content scripts you have to use Message Passing to achieve that. The reason, they both belong to different domains, which make sense. There are many examples in the Message Passing page for you to check out.



Hope that clears everything.


[#95458] Monday, September 27, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
juancarlos

Total Points: 580
Total Questions: 105
Total Answers: 103

Location: Grenada
Member since Sun, Dec 20, 2020
4 Years ago
;