Chrome extension popup installation

前端 未结 1 1864
北荒
北荒 2020-12-22 08:59

This is kind of a stupid question but i couldnt find any help searching around.

I would like to know how can i make my chrome extension, when its being installed by

相关标签:
1条回答
  • 2020-12-22 09:56

    For "when it is being installed", there is a special event in chrome.runtime API:

    onInstalled

    Fired when the extension is first installed, when the extension is updated to a new version, and when Chrome is updated to a new version.

    As you guessed correctly, it should go to your background script.

    chrome.runtime.onInstalled.addListener( function(details) {
      switch(details.reason) {
        case "install":
          // First installation
          break;
        case "update":
          // First run after an update
          break;
      }
    });
    

    To open a new tab with your URL, you can use chrome.tabs

    chrome.tabs.create({url: "http://example.com/"});
    
    0 讨论(0)
提交回复
热议问题