Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Chrome extension (Fire a event when extension starts)

I want to fire a event just when my chrome extension starts. How do I achieve this? Is there a event listener that triggers when extension starts?

for example:-

chrome.runtime.onInstalled.addListener(function(){
        console.log('i will run once!');
});

Similar to this but not on installed but on start and it should only fire once during the extension's run time which is when it starts.

like image 999
m1alesis Avatar asked Jan 05 '15 19:01

m1alesis


People also ask

Is Google getting rid of Chrome extensions?

Although the blog post above says that existing Chrome Apps will continue to be supported into the future, Google has since reversed this decision, deciding to end Chrome Apps support in June 2022.

Why does Chrome keep disabling my extension?

If you see a message saying "Extensions Disabled," it's because Chrome has turned off one or more of your extensions to keep your data safe while you're browsing the Internet. The extensions that Chrome turned off either didn't come from the Chrome Web Store or were determined unsafe.

Can Chrome extensions be detected?

Yes, it is possible to detect extensions, so long as you know your extension ID (which I'm sure you do).

How do I fix Chrome extension errors?

In the task manager, locate the extension and tap End Process. This will disable the extension from the browser. Now, go to More Tools > Extensions and give the extension a fresh start by tapping on Reload. Even after the fixes above, if the extension doesn't load correctly, uninstall it and reinstall it.


1 Answers

You could use an onload event in your background page and put the code that you want to be executed on extension "start-up" in there.

Example (inside background.js):

window.onload = function() {
  console.log("Extension has started...");
};

That message will be logged (once) when:

  • Extension is installed
  • Chrome is started (and extension is enabled)
  • Extension is enabled from disabled state
like image 62
berrberr Avatar answered Sep 24 '22 21:09

berrberr