Skip to content

Commit 063e857

Browse files
author
Maura Winstanley
committed
format and delete old file
1 parent 6656fd8 commit 063e857

2 files changed

Lines changed: 19 additions & 139 deletions

File tree

specs/APIReview_UAString

Lines changed: 0 additions & 101 deletions
This file was deleted.

specs/APIReview_UAString.md

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
11
# Background
2-
The User Agent is a client-side piece of information that the browser/webcontrol sends to the server/website a user visits.
3-
It contains information about user’s system and is modifiable by the user.
2+
The User Agent is a client-side piece of information that the browser/webcontrol sends to the server/website a user visits. It contains information about user’s system and is modifiable by the user.
43

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

10-
However,
11-
there are a couple limitations to this workaround-- you
12-
cannot modify a command line switch at runtime,
13-
nor can you change the user agent per webview
14-
.
15-
16-
In this document we describe the new API
17-
.We'd appreciate your feedback.
8+
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.
189

1910
# Description
20-
The Settings component will change the UA per WebView2 via Chrome Developer
21-
Protocol command.(CDP)
22-
A key scenario is to allow end developers to get the current user
23-
agent from the webview and modify it based on some sort of event,
24-
such as navigating to a specific website and setting the user agent to
25-
emulate a different browser version
26-
.
11+
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.
2712

2813
# Examples
2914

@@ -41,16 +26,18 @@ m_webView->add_NavigationStarting(
4126
wil::unique_bstr domain = GetDomainOfUri(uri.get());
4227
const wchar_t *domains = domain.get();
4328
if (wcscmp(url_compare_example, domains) == 0) {
44-
wil::com_ptr<ICoreWebView2Settings> settings;
45-
CHECK_FAILURE(m_webView->get_Settings(&m_settings));
46-
LPCWSTR mobile_ua =
47-
"Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) "
48-
"AppleWebKit/537.36 (KHTML, like Gecko) "
49-
"Chrome/62.0.3202.84 Mobile Safari/537.36";
50-
CHECK_FAILURE(settings->put_UserAgent(mobile_ua));
51-
LPCWSTR received_ua;
52-
CHECK_FAILURE(settings->get_UserAgent(&received_ua));
53-
EXPECT_EQ(base::Value(received_ua), base::Value(mobile_ua))
29+
// Upon navigation to a specified url
30+
// Change the user agent to emulate a mobile device
31+
wil::com_ptr<ICoreWebView2Settings> settings;
32+
CHECK_FAILURE(m_webView->get_Settings(&m_settings));
33+
LPCWSTR mobile_ua =
34+
"Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) "
35+
"AppleWebKit/537.36 (KHTML, like Gecko) "
36+
"Chrome/62.0.3202.84 Mobile Safari/537.36";
37+
CHECK_FAILURE(settings->put_UserAgent(mobile_ua));
38+
LPCWSTR received_ua;
39+
CHECK_FAILURE(settings->get_UserAgent(&received_ua));
40+
EXPECT_EQ(base::Value(received_ua), base::Value(mobile_ua))
5441
}
5542
return S_OK;
5643
})
@@ -61,12 +48,9 @@ m_webView->add_NavigationStarting(
6148
## .NET and WinRT
6249
6350
```c #
64-
private void SetUserAgent(CoreWebView2 sender,
65-
CoreWebView2UserAgentArgs e) {
51+
private void SetUserAgent(CoreWebView2 sender, CoreWebView2UserAgentArgs e) {
6652
var settings = webView2Control.CoreWebView2.Settings;
67-
settings.UserAgent = "Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F "
68-
"Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) "
69-
"Chrome/62.0.3202.84 Mobile Safari/537.36";
53+
settings.UserAgent = "Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36";
7054
}
7155
```
7256

@@ -98,10 +82,7 @@ public
9882
partial class CoreWebView2 {
9983
// There are other API in this interface that we are not showing
10084
public
101-
CoreWebView2Settings UserAgent {
102-
get;
103-
set;
104-
};
85+
CoreWebView2Settings UserAgent {get ; set; };
10586
}
10687
}
10788
```

0 commit comments

Comments
 (0)