Skip to content

Commit 2c2527d

Browse files
author
Maura Winstanley
committed
format, change get input
1 parent 05f48b3 commit 2c2527d

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

specs/APIReview_UAString.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
# Background
22

3-
43
Currently, a developer can pass the --user-agent browser args to the CreateWebView2EnvironmentWithDetails function.
54
Ex. CreateWebView2EnvironmentWithDetails(nullptr, nullptr, L"--user-agent=\"myUA\"", ...);
65
For more info about the ‘—user - agent’ flag visit: https://peter.sh/experiments/chromium-command-line-switches/#user-agent.
76

87
However, there are a couple limitations to this workaround-- you cannot modify a command line switch at runtime, nor can you change the user agent per webview. In this document we describe the new API. We'd appreciate your feedback.
98

10-
--
11-
12-
The Settings component will change the UA per WebView2 via Chrome Developer Protocol command (CDP). A key scenario is to allow end developers to get the current user agent from the webview and modify it based on some sort of event, such as navigating to a specific website and setting the user agent to emulate a different browser version.
13-
14-
159
# Description
1610

1711
The User Agent (UA) is a client-side piece of information that the browser/webcontrol sends to the server or website a user visits. It contains information about user’s system and is modifiable by the user.
1812

1913
The User Agent String API allows developers to modify WebView's user agent string via Chrome Developer Protocol (CDP). The user agent can be changed based on different events such as navigation to a specific website.
2014

15+
The Settings component will change the UA per WebView2 via Chrome Developer Protocol command (CDP). A key scenario is to allow end developers to get the current user agent from the webview and modify it based on some sort of event, such as navigating to a specific website and setting the user agent to emulate a different browser version.
16+
2117
# Examples
2218

2319
The following code snippet demonstrates how the environment APIs can be used
@@ -45,7 +41,7 @@ m_webView->add_NavigationStarting(
4541
CHECK_FAILURE(settings->put_UserAgent(mobile_ua));
4642
LPCWSTR received_ua;
4743
CHECK_FAILURE(settings->get_UserAgent(&received_ua));
48-
EXPECT_EQ(base::Value(received_ua), base::Value(mobile_ua))
44+
EXPECT_STREQ(received_ua, mobile_ua);
4945
}
5046
return S_OK;
5147
})
@@ -76,7 +72,7 @@ See [API Details](#api-details) section below for API reference.
7672
interface ICoreWebView2StagingSettings : IUnknown {
7773
/// `UserAgent` . Returns the User Agent. The default value is the
7874
/// default User Agent.
79-
[propget] HRESULT UserAgent([ out, retval ] LPCWSTR * userAgent);
75+
[propget] HRESULT UserAgent([ out, retval ] LPWSTR * userAgent);
8076
/// Sets the `UserAgentString` property. This property may be overriden if
8177
/// the User-Agent header is set in a request.
8278
[propput] HRESULT UserAgent([in] LPCWSTR userAgent);

0 commit comments

Comments
 (0)