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

前端 未结 4 1592
忘了有多久
忘了有多久 2020-12-13 01:07

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 see

4条回答
  •  半阙折子戏
    2020-12-13 01:39

    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"});
    }
    

提交回复
热议问题