Make wallpaper visible in the Google Chrome extension

I have a background-page in my Google Chrome extension and this page is naturally invisible. In any case, in order to make this hidden page visible, say, in a popup when the browser action icon is clicked? Then hide it again with a click.

+4
source share
3 answers

The background page can be displayed using the chrome.tabs.create method, which requires tabs permission . For example, if your background page is called background.html , you can use the following code:

 chrome.tabs.create({url: chrome.extension.getURL('background.html')}); 

See also:

+6
source

You can open backround_page in browserAction popup . However, this will be a new example of background_page . One of them is like a pop-up window while it is open, and durable invisible in the background.

0
source

On the pop-up page of your extensions, add the part of JS, which utilities are chrome.runtime.getBackgroundPage (callback) . Set the background page <html> id and use window.getElementById("myBackgroundPageHTMLElementId")

For example, your callback might look like this:

 document.getElementById("myPopupHTMLElementId").outerHTML = backgroundWindow.getElementById("myBackgroundPageHTMLElementId").outerHTML 

After completing this JS script, the HTML element of your popup page will be FULLY replaced by the background page (until you reload it)! This means that all attributes, even in the HTML element, are set to the version of the background page.

Hope this helps!

0
source

Source: https://habr.com/ru/post/1400879/


All Articles