1

I can see nothing in google's documentation to indicate how to prevent a user from closing a chrome app. Has anyone come up with a way to accomplish this? I think there is clue in the documentation about the onSuspend event. It says - After receiving onSuspend no further events will be delivered to the app, unless the suspension is aborted for some reason.

How can the suspension be aborted?

Ian
  • 572
  • 1
  • 4
  • 17
  • @wOxxOm it seems a reasonable requirement for a kiosk app. – Ian Jul 13 '16 at 13:14
  • `onSuspend` relates to shutting down the background page of the app after all windows closed. I assume you want to keep the app's window open instead? – Xan Jul 13 '16 at 13:24
  • @Xan yes I do want to do that. I want to intercept the app closing process and stop it. – Ian Jul 13 '16 at 13:26
  • 1
    What about a [frameless app window](https://github.com/GoogleChrome/chrome-app-samples/tree/master/samples/frameless-window) and intercepting keyboard shortcuts that may close the window? – wOxxOm Jul 13 '16 at 13:32
  • @wOxxOm what about ending the process from task manager? – Ian Jul 13 '16 at 13:59
  • That's extra brutal. You will have to write a native code utility for each supported OS that intercepts system-level messages. Even in this case it could be closed by something like Process Hacker (an advanced task manager), which has a kernel-mode driver. – wOxxOm Jul 13 '16 at 14:18
  • Why would you want to do this? – Daniel Herr Jul 13 '16 at 20:50
  • @Daniel Herr why would you want a user being able to close a kiosk app on a chromebook made available to the general public? Surely, you'd want to ensure that the app was available at all times. – Ian Jul 14 '16 at 07:14
  • Why don't you just use kiosk mode? – Daniel Herr Jul 14 '16 at 07:14
  • @Daniel Herr ok, that isn't the reason I have in mind actually. I'd prefer to keep the actual reason to myself :-). – Ian Jul 14 '16 at 07:16

1 Answers1

0

Some events can trigger an onSuspendCancel. I found that making a new XMLHttpRequest to any URL will do the trick. You could also call chrome.runtime.reload and make the app start anew.

In general there should be no need to prevent the background page from suspending, because it can be woken up with either a persistent listening socket, or runtime message, or google cloud message, etc.

If you just want to prevent the user from closing an app window, there is no way to do this, apart from implementing your own custom app window frame and intercepting for example control-w. You need to just save your work or app state outside the window context (should not be too hard to do this) so that you can still have it even when the window is closed unexpectedly.

kzahel
  • 2,765
  • 1
  • 22
  • 31
  • I accepted this answer because it says that "some events" trigger onSuspendCancel and a colleague found that too. It would be nice ig Google documented this properly. I'd like to know what all these events are. – Ian Jul 14 '16 at 07:10
  • I would like to know this too. There is some documentation that says onSuspend will trigger when there are no pending callbacks, etc. But I found onSuspend is triggered despite there being pending callbacks, etc. So clearly there are other conditions (such as low on RAM?) that trigger onSuspend. XHR is the only way I know how to trigger onSuspendCancel, and I tried a few different things. – kzahel Jul 14 '16 at 13:06
  • you may be interested in this. http://stackoverflow.com/questions/38372469/chrome-app-window-onclosed-not-fired-when-process-ended-from-task-manager-goog/38373504#38373504 – Ian Jul 14 '16 at 13:24