Haroon Dilshad
Haroon Dilshad

Reputation: 97

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

Upvotes: 9

Views: 14355

Answers (1)

Xan
Xan

Reputation: 77571

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.

Upvotes: 18

Related Questions