How do I access the popup page DOM from bg page in Chrome extension?

A background page is a page that lives forever for the life time of your extension. While the popup page only lives when you click on the popup In my opinion, it should be refactored the other way around, your popup should request something from the background page. You just do this in the popup to access the background page: chrome.extension.

GetBackgroundPage() But if you insist, you can use simple communication with extension pages with sendRequest() and onRequest Perhaps you can use chrome.extension.getViews.

A background page is a page that lives forever for the life time of your extension. While the popup page only lives when you click on the popup.In my opinion, it should be refactored the other way around, your popup should request something from the background page. You just do this in the popup to access the background page: chrome.extension.

GetBackgroundPage() But if you insist, you can use simple communication with extension pages with sendRequest() and onRequest. Perhaps you can use chrome.extension.getViews.

Yesterday as I was investigating I realized the popup seems to be transient; scripts are reloaded each time it is opened. I had assumed it was a persistent object. But now I see any popup state needs to be stored in the background and loaded when the popup is opened.

– Fletcher Moore May 5 '10 at 12:09.

I understand why you want to do this as I have run into the problem myself. The easiest thing I could think of was using Google's method of a callback - the sendRequest and onRequest methods work as well, but I find them to be clunky and less straightforward. Content.

Js chrome.extension. GetBackgroundPage(). DoMethod(function(params) { // Work with modified params // Use local variables }); Background.

Html function doMethod(callback) { if(callback) { // Create/modify params if needed var params; // Invoke the callback callback(params); } } HTH.

That will not work, you cannot access the background page from the content script. They live in different worlds. The only way you can access the background page from the content script is through Messaging.

You can do a quick search on stackoverflow for some examples. – Mohamed Mansour Jan 4 at 3:19 @Mohamed: The question is about a popup page, not a content script. – Eric Sep 25 at 8:49.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions