Search code examples
lifecyclegoogle-chrome-app

Chrome App Lifecycle


I'm reading through Chrome App Lifecycle. The model looks very simple. There's an onLaunch and onSuspend.

A few questions:

1) Is it possible to detect a transition from foreground to background?

2) Does Chrome persist any state automatically before moving to the background?

3) Does Chrome snap a capture of the app's window before moving to the background?

4) Does the same apply to Chrome Packaged Apps?


Solution

  • 1) Yo'll only receive onSuspend event right before event page become inactive. If you want to know when the user close app's window you need to listen for page unload event in the app an inform event page about the fact (using chrome.runtime API).

    2) If you set "id" parameter for chrome.app.window.create options object, Chrome will persist window state: width, height, top and left position and screen number and restore it during next app bootstrap. You can override this behavior setting your own values in chrome.app.window.create method.

    3) As far as I know - no.

    4) No. It is different kind of apps.