Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting WebView2 vs standalone Edge browser?

I have a page that needs to render differently depending on whether it's being viewed from a WebView2 component (inside another application) or from a standalone Microsoft Edge browser. I tried distinguishing the two via the user agent string, but the strings are more or less identical (both contain "Edg"). Does anyone have a method to distinguish between a WebView2 and an Edge browser?

like image 382
dB' Avatar asked Dec 18 '25 02:12

dB'


1 Answers

I stumbled upon this question a bit late, apparently, but there's a very specific way to detect WebView2 because the engine injects several members into the window object, including iFrames. For example, the method window.gc is something that won't normally exist, but let's see what happens in a WebView2 engine:

if ("gc" in window) alert("WebView2");

Detecting WebView2

If you don't want to check the main window. you can do it from an emtpy iFrame, which will return true as well.

like image 85
Manuel Caballero Avatar answered Dec 20 '25 14:12

Manuel Caballero



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!