Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome extension background page inactive makes the extension run on 2 clicks

I have an extension which runs on a background page, the browserAction icon requires 2 clicks at max few seconds apart for the extension to start running background.js so I tried to see what's the issue, with chrome://extensions page loaded which states for my extension:Background page inactive. When I click one time the state changes to background page active and then the next click actually runs the extension, I couldn't see what's the issue, I use chrome.runtime.reload() at a couple of places, maybe that's the issue but what's the solution? Thanks in advance

like image 322
Haroon Dilshad Avatar asked Sep 26 '14 22:09

Haroon Dilshad


People also ask

Does Chrome extension work in background?

This extension simply keeps Chrome running in the background, so that push notifications can be received while the browser is closed.

What does background script do in Chrome extension?

The background script is a script running in the background to handle majority of chrome events that content scripts cannot. Content scripts are purely the content of the each page.

Why does my Chrome extension keep turning off?

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.


1 Answers

A background page can become inactive if it's declared as an Event page ( "persistent": false in the manifest).

Which probably means that you haven't set it up correctly if events are only handled after causing them twice.

Obvious solution: drop "persistent": false from the manifest. This is not recommended unless you use things that cannot work with Event pages (currently, mainly webRequest API)

Proper solution: see if your background script can be made into a proper Event page.

like image 147
Xan Avatar answered Sep 21 '22 13:09

Xan