Reputation: 25830
In my manifest I have:
"app":
{
"background":
{
"scripts":
[
"main.js"
],
"persistent": true
}
}
but it still shows Inspect views: _generated_background_page.html (Inactive)
and when I look at the console, it is inactive.
And I also have a setInterval
running every 10 seconds. Yet, it still goes inactive!
What do I need to do to keep it from going inactive?
Additional Info:
I added an alarm that fires every minute and this appears to wake my app up. (Need to do more testing) But it means waiting a minute after Chrome startup before the app runs.
Upvotes: 5
Views: 5346
Reputation: 4508
One approach would be to have your web service host the helper app, and notify the other apps as necessary. This seems the most "chromium" way (whatever that means). But that would involve an app on one computer messaging an app on another computer, which seems complicated, at best.
You could also try "permissions": ["background"]
(reference).
It appears extensions are allowed persistent background pages, whereas apps aren't. You could change your helper app into a helper extension that messages the other apps.
Upvotes: 4
Reputation: 18610
Run your code when it needs to run, you don't need a background page running constantly to do so. E.g. use chrome.runtime.onInstalled, chrome.runtime.onStartup, chrome.app.runtime.onRestarted, etc to trigger code on those events. The Alarms API to wake up occasionally, Push Messaging to be woken up by your sever, or launch a window if there is interface a user should interact with.
The application can be restarted at any time - so always keep your state saved.
Upvotes: -3