Keep Popup Open when Opening a new Page

后端 未结 2 1013
遥遥无期
遥遥无期 2021-01-28 21:25

I have the following code to introduce my Chrome Extension.

// detect if this is the first time running
var first_run = false;
if (!localStorage[\'ran_before\'])         


        
相关标签:
2条回答
  • 2021-01-28 21:53

    the method you are using is valid and should work, but you should probably just use the onInstalled event for consistency:

    chrome.runtime.onInstalled.addListener(function(info){
        if(info.reason == "install"){
            console.log("Installed!");
        }else if(info.reason == "update"){
            console.log("Updated!");
        }
    });
    

    It doesn't require new permissions, and will keep your install code clearly separated from the rest of your code.

    0 讨论(0)
  • 2021-01-28 22:02

    While Marc Guiselin's answer is excellent, it may be useful to know how to open a tab without closing a popup.

    You could open the tab in the background, that way it won't close your popup.

    chrome.tabs.create({
      url: chrome.runtime.getURL("intro/index.html"),
      active: false
    });
    

    In general, you should avoid using window.open in extensions and use chrome.tabs and chrome.windows API instead.

    0 讨论(0)
提交回复
热议问题