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?
Detecting WebView2 vs standalone Edge browser?
1.3k views Asked by dB' At
2
There are 2 answers
0
Manuel Caballero
On
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");
If you don't want to check the main window. you can do it from an emtpy iFrame, which will return true as well.
Related Questions in JAVASCRIPT
- Using Puppeteer to scrape a public API only when the data changes
- inline SVG text (js)
- An array of images and a for loop display the buttons. How to assign each button to open its own block by name?
- Storing the preferred font-size in localStorage
- Simple movie API request not showing up in the console log
- Authenticate Flask rest API
- Deploying sveltekit app with gunjs on vercel throws cannot find module './lib/text-encoding'
- How to request administrator rights?
- mp4 embedded videos within github pages website not loading
- Scrimba tutorial was working, suddenly stopped even trying the default
- In Datatables, start value resets to 0, when column sorting
- How do I link two models in mongoose?
- parameter values only being sent to certain columns in google sheet?
- Run main several times of wasm in browser
- Variable inside a Variable, not updating
Related Questions in WEBVIEW
- Android jetpack compose webview, image selector not works
- After progressbar load website is not loading in android webview
- Awaited promise for navigator.mediaDevices.getUserMedia neither resolves or throws an error
- Flutter WebViewWidget inside StatefulWidget does not dispose
- Crash : org.chromium.android_webview.AwDataDirLock.b
- Tauri Build Error unterminated character in import
- Update your browser to use...in android webview application
- Face Recognition in Windows Logon
- Flutter Webview translate the page
- Prevent checking checkbox input in contentEditable from stealing focus from editor in Android webview?
- Touch Problem with slider on Android 12 compared to Android 8 in vuejs webapp in WebView
- Asset file not being included on older versions of Android
- Unable to Trigger JavaScript Actions in WKWebView for W3Schools "Try it Yourself" Button (iOS/UIKIT)
- TadingView Charts in Flutter Dart are responsive on App
- Flutter webview fails to load Urls with error 'ERR_INVALID_RESPONSE' on Android but works on iOS
Related Questions in MICROSOFT-EDGE
- couldn't sign in visual studio code
- Could not start a new session. Response code 500
- C# --headless print-to-pdf with Microsoft edge(chromium) won't work using ProcessStartInfo
- Building a web application for microsoft edge sidebar
- How to access Microsoft Edge browser and login into website via VBA
- Testcases failing in azure pipeline giving error edge driver exception
- Have values for edge driver changed
- DevTools not evaluating `$0` eagerly
- Native Messaging "Specified native messaging host not found" debugging
- @angular/cdk drag and drop dropzone likes to be outside of the original position when dropping in chrome browser but works fine in edge
- Start MS-Edge from command with save-as enabled
- img tag not loading dynamic image url in different browser except chrome
- How to restore the Microsoft extension user data to another pc?
- chrome.downloads.download on MS Edge: windows update this week added a bug. Work-around?
- Several issues with scroll snap in HTML/CSS
Related Questions in BROWSER-DETECTION
- Unable to detect underlying OS using JS
- Can JavaScript detect the Arc browser?
- Detecting WebView2 vs standalone Edge browser?
- Dealing with Safari and .webp images in 2022
- What is the best way to handle different browser features within a Blazor Server-Side Application?
- How to detect specific browser version or higher (jQuery)
- Detect edge (chromium) browser using Javascript
- Uncaught ReferenceError when adding JS to app.js in Laravel
- How to detect if Xiaomi's Mi Browser using JS
- Prevent Canvas Fingerprinting in DotNetBrowser
- Checking browser using just CSS?
- How to detect Installed Browsers on a Mac Machine using Node.js?
- Is my Chrome driver detected and refused by EToro server?
- how to let my website open only on specific browsers
- Using jQuery to detect browser
Related Questions in WEBVIEW2
- Is it possible to get the user data folder without creating an instance of the WebView2 browser control?
- Issues with WebView2 in WPF Usercontrol Embeded in Word VSTO CustomTaskPane
- An HTML Link Element ("a") Refuses to Attach Itself to Event Listener
- C# Webview2 WebMessageReceived event not firing anymore after update of MS Edge browser and Webview2 runtime
- How to copy or drag n drop image from Webview2 to Canvas?
- Why Webview2 set value of an input element but value desapears after submiting the form as never had been set?
- WebView2 control not return Bing AI tool (COPILOT) output in windows form c#
- Paste from the clipboard into textarea that uses the class 'form-control rte' (Rich Text Editor)
- Using WebView2 with Microsoft Edge AppData
- Display HTML string in WebView2 control with VB.NET causes error
- Show images from HTMLBody of MailItem in WebView2
- How to get update information of Microsoft Edge Extensions
- How to make UWP WebView2 transparent?
- Send Post-Request with WebView2 -> postData does not reach the API endpoint
- How to draw a rectangle on Webview2 when its content is loaded?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)

There's no perfect way for web content to identify that is running within a WebView2 because the host app of the WebView2 can customize so many aspects of the WebView2.
For example, the host app can change the user agent via
CoreWebView2Settings.UserAgentto appear to be Chrome or any other browser. Or the host app can inject script usingCoreWebView2.AddScriptToExecuteOnDocumentCreatedAsyncand change the DOM or other objects in script.However, if you are trying to determine if your web content is running within your own app, you can use those same customizations I mention above as a way for the host app to signal to the web content that the web content is running within a WebView2.