Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically open a chrome extension popup window from background.html

Thanks in advance!

What I want to achieve is to open the popup window when a special tag is detected on a webpage by my extension. After searching for a while it seems like the popup can only be opened when user clicks the extension. Is it true?

Or could I get the location of my extension's icon on browser? Maybe I could draw a window and display under the extension icon to make it looks just like the popup window.

like image 729
Dahe80 Avatar asked Apr 04 '11 20:04

Dahe80


People also ask

Do Chrome extensions run in background?

Running in the background also allows any Chrome extensions you might have installed to continue to operate. These are applications that run within Chrome and either enhance the browser's existing features, or add new ones.

What is Chrome background HTML extension?

Background Pages. A common need for extensions is to have a single long-running script to manage some task or state. Background pages to the rescue. As the architecture overview explains, the background page is an HTML page that runs in the extension process.


2 Answers

This guy wants opposite effect and can't get his popup window not to open. Take a look at his code to open your popup page ;)

like image 50
Aleksandar Toplek Avatar answered Oct 19 '22 08:10

Aleksandar Toplek


It is impossible to get the extension window to open without a user clicking on it... However, you can get the extension popup page to open in a new tab as follows:

1) Set your background page in your manifest file...

"background_page": "background.html", 

This is where you will run the code to see whether the special tag is detected... background pages can constantly run code in the background, and it is up to you to set a repeat loop to check whether you variable condition is true every so often...

2) Enable tabs permission in your manifest file...

"permissions": [ "tabs" ], 

This permission is needed for step 3 (Allows the background page to open a new tab)

3) In background page, call create and point to the extension popup url.

if(condition == true){   chrome.tabs.create({url:"popup.html"}); } 
like image 36
David Avatar answered Oct 19 '22 10:10

David