|
| 1 | +The purpose of this spec is to describe a new WebView2 feature - Support for UA Strings - and its APIs. |
| 2 | + |
| 3 | +# Background |
| 4 | + |
| 5 | +A User Agent String is a client-side piece of information that the browser/webcontrol sends to the server/website a user visits. |
| 6 | +It contains information about user’s system and is modifiable by the user. |
| 7 | + |
| 8 | +Currently, a developer can pass the --user-agent browser args to the CreateWebView2EnvironmentWithDetails function. |
| 9 | + Ex. CreateWebView2EnvironmentWithDetails(nullptr, nullptr, L"--user-agent=\"myUA\"", ...); |
| 10 | + For more info about the ‘—user-agent’ flag visit: https://peter.sh/experiments/chromium-command-line-switches/#user-agent. |
| 11 | + |
| 12 | +However, there is a limitation to this workaround, in that you cannot modify a command line switch at runtime. |
| 13 | + |
| 14 | +In this document we describe the new API. We'd appreciate your feedback. |
| 15 | + |
| 16 | + |
| 17 | +# Description |
| 18 | + |
| 19 | +There are 2 locations for changing UA String in a WebView context: |
| 20 | + |
| 21 | +1. Settings – Changes UA per WebView2 via Chrome Developer Protocol. (CDP) |
| 22 | +2. Environment Options – sets UA once at creation for the WebView2 environment. |
| 23 | + |
| 24 | +We wanted to create an API that handles #1?? or #2? //jason to update |
| 25 | +We added an API that allows a user to ... |
| 26 | + |
| 27 | +# Examples |
| 28 | +<!-- TEMPLATE |
| 29 | + Use this section to explain the features of the API, showing |
| 30 | + example code with each description in both C# (for our WinRT API or .NET API) and |
| 31 | + in C++ for our COM API. Use snippets of the sample code you wrote for the sample apps. |
| 32 | + |
| 33 | + The general format is: |
| 34 | + |
| 35 | + ## FirstFeatureName |
| 36 | + |
| 37 | + Feature explanation text goes here, including why an app would use it, how it |
| 38 | + replaces or supplements existing functionality. |
| 39 | + |
| 40 | + ```c# |
| 41 | + void SampleMethod() |
| 42 | + { |
| 43 | + var show = new AnExampleOf(); |
| 44 | + show.SomeMembers = AndWhyItMight(be, interesting) |
| 45 | + } |
| 46 | + ``` |
| 47 | + |
| 48 | + ```cpp |
| 49 | + void SampleClass::SampleMethod() |
| 50 | + { |
| 51 | + winrt::com_ptr<ICoreWebView2> webview2 = ... |
| 52 | + } |
| 53 | + ``` |
| 54 | + |
| 55 | + ## SecondFeatureName |
| 56 | + |
| 57 | + Feature explanation text goes here, including why an app would use it, how it |
| 58 | + replaces or supplements existing functionality. |
| 59 | + |
| 60 | + ```c# |
| 61 | + void SampleMethod() |
| 62 | + { |
| 63 | + var show = new AnExampleOf(); |
| 64 | + show.SomeMembers = AndWhyItMight(be, interesting) |
| 65 | + } |
| 66 | + ``` |
| 67 | + |
| 68 | + ```cpp |
| 69 | + void SampleClass::SampleMethod() |
| 70 | + { |
| 71 | + winrt::com_ptr<ICoreWebView2> webview2 = ... |
| 72 | + } |
| 73 | + ``` |
| 74 | + |
| 75 | + As an example of this section, see the Examples section for the PasswordBox |
| 76 | + control (https://docs.microsoft.com/windows/uwp/design/controls-and-patterns/password-box#examples). |
| 77 | +--> |
| 78 | + |
| 79 | + |
| 80 | +# Remarks |
| 81 | +<!-- TEMPLATE |
| 82 | + Explanation and guidance that doesn't fit into the Examples section. |
| 83 | + |
| 84 | + APIs should only throw exceptions in exceptional conditions; basically, |
| 85 | + only when there's a bug in the caller, such as argument exception. But if for some |
| 86 | + reason it's necessary for a caller to catch an exception from an API, call that |
| 87 | + out with an explanation either here or in the Examples |
| 88 | +--> |
| 89 | + |
| 90 | + |
| 91 | +# API Notes |
| 92 | +<!-- TEMPLATE |
| 93 | + Option 1: Give a one or two line description of each API (type and member), |
| 94 | + or at least the ones that aren't obvious from their name. These |
| 95 | + descriptions are what show up in IntelliSense. For properties, specify |
| 96 | + the default value of the property if it isn't the type's default (for |
| 97 | + example an int-typed property that doesn't default to zero.) |
| 98 | + |
| 99 | + Option 2: Put these descriptions in the below API Details section, |
| 100 | + with a "///" comment above the member or type. |
| 101 | +--> |
| 102 | + |
| 103 | + |
| 104 | +# API Details |
| 105 | +<!-- TEMPLATE |
| 106 | + The exact API, in IDL format for our COM API and |
| 107 | + in MIDL3 format (https://docs.microsoft.com/en-us/uwp/midl-3/) |
| 108 | + when possible, or in C# if starting with an API sketch for our .NET and WinRT API. |
| 109 | + |
| 110 | + Include every new or modified type but use // ... to remove any methods, |
| 111 | + properties, or events that are unchanged. |
| 112 | + |
| 113 | + (GitHub's markdown syntax formatter does not (yet) know about MIDL3, so |
| 114 | + use ```c# instead even when writing MIDL3.) |
| 115 | + |
| 116 | + Example: |
| 117 | + |
| 118 | + ``` |
| 119 | + /// Event args for the NewWindowRequested event. The event is fired when content |
| 120 | + /// inside webview requested to open a new window (through window.open() and so on.) |
| 121 | + [uuid(34acb11c-fc37-4418-9132-f9c21d1eafb9), object, pointer_default(unique)] |
| 122 | + interface ICoreWebView2NewWindowRequestedEventArgs : IUnknown |
| 123 | + { |
| 124 | + // ... |
| 125 | + |
| 126 | + /// Window features specified by the window.open call. |
| 127 | + /// These features can be considered for positioning and sizing of |
| 128 | + /// new webview windows. |
| 129 | + [propget] HRESULT WindowFeatures([out, retval] ICoreWebView2WindowFeatures** windowFeatures); |
| 130 | + } |
| 131 | + ``` |
| 132 | + |
| 133 | + ```c# (but really MIDL3) |
| 134 | + public class CoreWebView2NewWindowRequestedEventArgs |
| 135 | + { |
| 136 | + // ... |
| 137 | + |
| 138 | + public CoreWebView2WindowFeatures WindowFeatures { get; } |
| 139 | + } |
| 140 | + ``` |
| 141 | +--> |
| 142 | + |
| 143 | + |
| 144 | +# Appendix |
| 145 | +<!-- TEMPLATE |
| 146 | + Anything else that you want to write down for posterity, but |
| 147 | + that isn't necessary to understand the purpose and usage of the API. |
| 148 | + For example, implementation details or links to other resources. |
| 149 | +--> |
0 commit comments