Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS Edge has a window.chrome object?? Breaks browser detection

What is up with MS Edge having an object called window.chrome same name as the one in Google Chrome.

For me this is breaking browser detection code for Chrome polyfills. I am imagining that this will cause problems for others too.

Using:

Edge: 25.10586.0.0

Edgehtml: 13.10586

The Edge window.chrome object has less stuff in it. Its only child object is window.chrome.app whereas the Chrome version has app, webstore, and runtime (Chrome version 49.0.2623.110, 64-bit).

Why would they do this? I could see making a proper window.chrome object with all the functionality but making a crippled one seems like it would do more damage than help anything.

Anyone encountered this? I've looked around and cant find anything. Thanks!

like image 335
StayCool Avatar asked Apr 05 '16 14:04

StayCool


2 Answers

"you should be checking features not browsers"

Spoken like someone who has never encountered a feature that exists in multiple browsers but does not function, or function the same, in all browsers it appears in.

My own recent case, I had a small function that has worked in all browsers for at least 12 years, since before Chrome even existed. The function just fires off a custom url which is registered on the client OS to run an external handler. So it just launches the custom url in a child _blank window and immediately closes it that child window.

function foo(stuff,otherstuff) {
  t = window.open("myproto://"+stuff,"_blank");
  t.close();
  window.location.replace("path/to/...?"+otherstuff);
}

Chrome, and only Chrome, and only recently sometime in late 2016 or so, changed window.open() so that it no longer blocks, so now to work around that I have to do:

t = window.open("myproto://"+stuff,"_blank");
t.addEventListener('load',t.close());

Ok, not the end of the world, except, not all browsers have that function...

Wait, wait don't tell me... "Test for the FEATURE!!!!"

Why didn't I think of that? Maybe because, guess what, Edge HAS the feature, and it DOESN'T behave properly.

So here I am googling for ways to detect Chrome, BY NAME, FOR A REASON.

Should I not only test for the existence of the feature, but also construct some kind of test that actually tries to invoke the feature, to see if it worked right? The thing I'm testing happens to be window opening and closing behavior. I can't be popping up junk windows, that then get stuck and don't close themselves, every time the damned page loads, or every time the user clicks on the damned button that needs the feature...

and if !!window.chrome is no longer viable because once again Edge, then I'm back to THIS utter buffoonery I guess:

var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
like image 65
Brian White Avatar answered Oct 10 '22 08:10

Brian White


I know you have marked the above answer but if you really want to detect Google Chrome browser by Google, I will suggest you to use something like this:

var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
like image 35
Anil Avatar answered Oct 10 '22 07:10

Anil