Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background Page in popup- chrome extension

I am embedding a dynamic webpage in a popup. Currently its working and every time popup is loaded the webpage is loaded again, thus me losing the work i did on the webpage in popup. Though its fine, but i want that webpage remain loaded in background and i just show it in popup on click. to do this i copied complete code from my pop up page(script+html) to background.html. Now how should i access the page completely in popup and show directly(i want to show html also-from background page)

Thanks

like image 952
Himz Avatar asked Feb 09 '11 07:02

Himz


People also ask

What is chrome background page extension?

Background pages are implicit pages which contain background scripts. A background script is a single long-running script to manage some task or state. It exists for the lifetime of your extension, and only one instance of it at a time is active.

How do you send a message from the background script to a popup script?

forEach((tab) => { chrome. tabs. sendMessage( tab.id, youtPayload, function (response) { // do something here if you want } ); }); }); That's it!

Can Chrome Extensions run in background?

Chrome 10 Now Lets Extensions Run in the Background.


1 Answers

Popups live in the same process (the extension process) as the background page, and one page can get the DOM Window of the other. A popup gets the background page by calling chrome.extension.getBackgroundPage(). So every time you open the popup, just read and write to some variable on the background page, for example chrome.extension.getBackgroundPage().enteredData = "value";.

Alternately, you can use HTML5 localStorage to store variables even after the browser is shut down; e.g. localStorage['enteredData'] = "value".

like image 96
yonran Avatar answered Sep 20 '22 21:09

yonran