Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can Chrome extension get a callback when the browser starts?

I need a way in my Chrome extension to know when the browser is starting up, so that it can automatically open an html page. Is there a mechanism in Chrome extension API that can get me this facility?

I need this functionality for a personal extension of mine, that I use only on my computer. So it's ok if this can be accomplished through a hack. My extension would like to know when the browser has started.

Any ideas?

like image 926
Jayesh Avatar asked Jun 14 '12 14:06

Jayesh


People also ask

Do Chrome extensions work automatically?

When you turn on Google Chrome browser sync, then all your chrome extensions will be automatically installed on all your devices. Also, the settings and state for all these extensions will be the same on all your devices.

How does a Chrome extension work?

Chrome extensions are built with HTML, JavaScript, and CSS scripts and are essentially small websites uploaded to the Chrome store. The only difference between a Chrome extension and a regular website is that extensions contain a manifest file, which gives them a specific function to execute.


2 Answers

if you want the tab to open when Chrome is started up, you can just include the code: chrome.tabs.create({url:"someUrl"}); in your background.js file or if you want it to open everytime a new window opens, you can include the previous code plus an extra event listener to the new window event like this:

chrome.windows.onCreated.addListener(function() {
chrome.tabs.create({url:"someUrl"});
})
like image 195
Sophie Avatar answered Oct 17 '22 02:10

Sophie


Scripts in background page start only one time on each browser start, so you just need to add background page to your extension to handle browser start.

like image 10
KAdot Avatar answered Oct 17 '22 02:10

KAdot