Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a new tab after installing the extension?

I need to open a newtab ( that point to a link that show how to use my extension ) after installing the extension. How can I do that ?

like image 996
xRobot Avatar asked Dec 04 '22 03:12

xRobot


2 Answers

You can have the background page check for a hasSeenIntro key in local storage on page load, which happens each time the browser loads, and when the browser is installed. If it's there, the user has seen the intro interstitial, and if not, show them the page (using chrome.tabs.create) then set the key.

Somewhere in your background.html:

if (!window.localStorage.getItem('hasSeenIntro')) {
  window.localStorage.setItem('hasSeenIntro', 'yep');
  chrome.tabs.create({
    url: '/help.html'
  });
}

You could extend this to show an intro for each new major version/feature in the extension, by not only checking the presence/absence of the key in local storage, but the value as well (e.g., last-seen feature page).

Be careful with this though, it may get annoying to show a page every time the extension updates itself.

like image 65
Jason Hall Avatar answered Jan 05 '23 00:01

Jason Hall


You can use the onInstalled listener. It will open options.html only once when the user install the Chrome extension.

chrome.runtime.onInstalled.addListener(function (){
    chrome.tabs.create({url:chrome.extension.getURL("options.html")},function(){})
})
like image 30
Ivan Belchev Avatar answered Jan 05 '23 01:01

Ivan Belchev