Chrome API: Get Window Type
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
?
--app=URL
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();
if (window is app) //I don't really care how it's done
doSomething();
More information:
I added more information. The JavaScript that I want to get the window type is running in the app, and not an extension. Also I've been unable to get that API to work in an app, extension, normal window, or anything else so clearly I'm doing something wrong.
– Zoltan Smith
Aug 22 at 4:24
2 Answers
2
Can you try the following. In your console
windowType=window.location.host
It should return if you are in app window it will return as "app". Using this you can write your logic
if (windowType === 'app' ) //I don't really care how it's done
doSomething();
Hope it helps.
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.
windowType.window.location.host
--app=url
(Thanks Ragavan Rajan)
You are welcome. Hope it helped you in some way.
– Ragavan Rajan
Aug 31 at 1:01
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Extensions aren't apps so you can't use their API.
– wOxxOm
Aug 20 at 4:12