2

I am trying to create a Chrome extension (or app) for Chrome OS that monitors the foreground app that the user is currently interacting with.

For example if the user:

  1. plays Angry Birds for a few minutes; then
  2. browses some web pages using Chrome and finally
  3. does some calculations using the Calculator

then I want my extension (or app) to be able to detect and respond to these three transitions as they occur. Ideally the information about the app that I'd like to capture is either the app name (e.g. "Angry Birds") and/or the app id (e.g. com.somecompany.someapp).

I already experimented with several of the chrome.* API's but so far I haven't had any luck:

  • chrome.windows and chrome.tabs can only enumerate browser windows/tabs (not those of apps).
  • chrome.app.window can only enumerate windows that are part of it's own app (not other apps).
  • Apps are only sent their own chrome.app.runtime lifecycle events and not those of other apps.
  • I might be able to use OCR on the screen cast provided by chrome.desktopCapture but I would probably have to write specific code for each app that I want to support and it would be very CPU intensive.

I have had luck doing similar work on other platforms (Windows, Mac, Linux and even Android) using accessibility client API's (same API's used by screen readers for disabled people). Unfortunately Chrome OS doesn't appear to facilitate 3rd party accessibility clients.

qypsac
  • 21
  • 1
  • I dont think that is possible. But why do you want to treat apps differently than sites? – Daniel Herr Jul 18 '16 at 03:47
  • @DanielHerr I don't want to treat apps differently. As I explained in my question it's the chrome.* API's that treat them differently. The chrome.* API's return information about browser windows/tabs not *not* app windows. – qypsac Jul 18 '16 at 04:39
  • I think this can be implemented via [Native Messaging](https://developer.chrome.com/extensions/nativeMessaging). – wOxxOm Jul 18 '16 at 07:11
  • @wOxxOm From what I gather [Native Messaging](https://developer.chrome.com/extensions/nativeMessaging) is just an API to communicate with native processes... How would I use this to identify the foreground app? – qypsac Jul 18 '16 at 07:30
  • You would create a native application that users install separately. – wOxxOm Jul 18 '16 at 07:40
  • @wOxxOm On _Chrome OS_? Good luck with that. – Xan Jul 18 '16 at 09:58
  • @wOxxOm How can the native process detect the foreground app? – qypsac Jul 18 '16 at 10:37
  • Apparently, I was wrong, sorry. – wOxxOm Jul 18 '16 at 10:50
  • @wOxxOm any luck were you able to get the foreground app details from your extension – jan_kiran Feb 02 '21 at 11:55

2 Answers2

1

There's a feature request to add more window types to the results of chrome.windows.getAll() -- See http://crbug.com/394341

moobag
  • 199
  • 1
  • 1
0

Chrome Extension and App APIs are listed here: Extensions, Apps.

(Un)fortunately, there isn't anything there that would allow spying on the user activity outside your context. Apps are generally limited to what happens in them (plus some hardware notifications), and extensions are generally limited to what happens in the browser.

You can detect focus loss in the browser/app, but you can't tell where the focus went.
For example, chrome.windows.onFocusChanged extension event will report -1 for all windows that are not part of the browser, even if it's a Chrome App.

Xan
  • 74,770
  • 16
  • 179
  • 206