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 best solutions below
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
- Equivalent of CEF's OnLoadingStateChange in WebView2
- Manage/Delete cookies of working WebView2
- This page is having a problem. c# Webview2
- Access WebView2 newly opened window
- Issues with the UserDataFolder property for Webview2
- Is there a Registry value to get Edge browser's user data location?
- How to wait for completion of a call to ExecuteScript on a WebView2 interface in a C++ COM STA
- add dependency to .exe and execute with parameter from MSIX installer
- Dll Unable to use in my project keep getting error upon referencing them
- I am unable to hit WebMessageReceived event using callback function from web page using VB.Net
- WebView2 blank page when publishing WinUI3 app through DevOps pipeline due to 32-bit DLL file being included
- Printing multiple copies using ICoreWebView2's Print function
- Webview2 multithreading freezes/stops
- ApplicationManager_ImmersiveShellWindow?
- How to show a caret in a WebView2 control?
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)
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?

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.