Search code examples
javascriptwindowgoogle-chrome-devtoolsgoogle-chrome-appchromium

Chrome API: Get Window Type


I'm working on a project and run into an issue where I need to distinguish a chrome app window from normal ones. (Specifically I'm using the --app=URL from a bash script) Because of the way things are setup, I have to have run a js script on all windows, but only do something if they are an app window. It seems that the API listed here is what I need to distinguish one window from another, but all I've managed to get are errors saying that a function or object is undefined. So how am I suppose to get the window type from the API with something like window.type?

Additionally, if you know of some other way to tell the difference between chrome windows if they are an app window or not, then that would also work. I really just need to be able to do: if (window is app) //I don't really care how it's done { doSomething(); }

More information:

  • Tried in both Chrome and Chromium (both fully updated)
  • Using Ubuntu 18.04
  • JavaScript is running in the app window and not an extension (not developing an extension)

Solution

  • Doing windowType.window.location.host returned not the type of window but rather the url provided with the --app=url flag in my bash script. This means that if you open a normal window and go to the same url as provided in the app window, both would return the same url. However, since the normal window would be the same content just a different window type, the JavaScript code that I need to run on the webpage is the same, thus I would want it to run on both windows. So this solution works for me, but for anyone else who is looking for a window specific identifier, and not just a url, I suppose that is still up in the air.

    (Thanks Ragavan Rajan)