-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start in background mode #2841
Open
JosephJin0815
wants to merge
11
commits into
main
Choose a base branch
from
StartInBackgroundMode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Start in background mode #2841
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bbfee79
Create StartInBackgroundMode.md
172f88f
Update StartInBackgroundMode.md
ffb5062
Update StartInBackgroundMode.md
04fd33d
Update StartInBackgroundMode.md
e758267
Update StartInBackgroundMode.md
a967880
Update StartInBackgroundMode.md
79ddf25
Update StartInBackgroundMode.md
897e7d6
Update StartInBackgroundMode.md
7c01a45
Update StartInBackgroundMode.md
018e420
StartInBackgroundMode.md
b84c803
Merge pull request #2781 from MicrosoftEdge/StartInBackgroundMode-draft
JosephJin0815 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,101 @@ | ||||||
CreationPriority | ||||||
=== | ||||||
|
||||||
# Background | ||||||
WebView2 has functionality enabled by default which raises the launch priority of WebView2 | ||||||
processes to ensure that WebView2 processes are given higher CPU priority and access to resources | ||||||
during creation, and that can bring improvements on time spent creating a WebView2 instance. Since | ||||||
this improvement is at the cost of taking higher CPU priority, we introduce the `CreationPriority` | ||||||
property to give developers an option to decide by themselves. | ||||||
|
||||||
# Description | ||||||
* Setting `CreationPriority` to `COREWEBVIEW2_CREATION_PRIORITY_NORMAL` will signal WebView2 | ||||||
to have normal priority compared to other processes during the creation of the WebView2 browser | ||||||
process. | ||||||
* Setting `CreationPriority` to `COREWEBVIEW2_CREATION_PRIORITY_HIGH` will attempt to enable | ||||||
raise the priority of the creation of the WebView2 browser process. | ||||||
* Default value is `COREWEBVIEW2_CREATION_PRIORITY_HIGH`. | ||||||
# Examples | ||||||
## Win32 C++ | ||||||
```cpp | ||||||
auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>(); | ||||||
/// Set the WebView2 browser process to have normal priority during | ||||||
/// creation, which avoids to impact other host application | ||||||
/// processes acquiring system resources. | ||||||
options->put_CreationPriority(COREWEBVIEW2_CREATION_PRIORITY_NORMAL); | ||||||
HRESULT hr = CreateCoreWebView2EnvironmentWithOptions( | ||||||
nullptr, m_userDataFolder.c_str(), options.Get(), | ||||||
Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>( | ||||||
this, &AppWindow::OnCreateEnvironmentCompleted).Get()); | ||||||
``` | ||||||
## WinRT and .NET | ||||||
```c# | ||||||
CoreWebView2EnvironmentOptions options = new CoreWebView2EnvironmentOptions(); | ||||||
options.CreationPriority = COREWEBVIEW2_CREATION_PRIORITY_NORMAL; | ||||||
CoreWebView2Environment Environment = | ||||||
await CoreWebView2Environment.CreateAsync( | ||||||
BrowserExecutableFolder, UserDataFolder, options) | ||||||
``` | ||||||
|
||||||
|
||||||
# API Details | ||||||
## Win32 C++ | ||||||
```cpp | ||||||
/// Specifies the type of webview2 creation priority for the | ||||||
/// `ICoreWebView2EnvironmentOptions3:CreationPriority` option. | ||||||
[v1_enum] | ||||||
typedef enum COREWEBVIEW2_CREATION_PRIORITY { | ||||||
COREWEBVIEW2_CREATION_PRIORITY_NORMAL, | ||||||
COREWEBVIEW2_CREATION_PRIORITY_HIGH, | ||||||
} COREWEBVIEW2_CREATION_PRIORITY; | ||||||
|
||||||
[uuid(efb58776-32bd-11ed-a261-0242ac120002), object, pointer_default(unique)] | ||||||
interface ICoreWebView2EnvironmentOptions3 : ICoreWebView2EnvironmentOptions2 { | ||||||
|
||||||
/// Gets the creation priority for webview2 creation. | ||||||
/// | ||||||
/// \snippet AppWindow.cpp CreateCoreWebView2EnvironmentWithOptions | ||||||
// MSOWNERS: wangsongjin@microsoft.com | ||||||
[propget] HRESULT CreationPriority([out, retval] COREWEBVIEW2_CREATION_PRIORITY* creationPriority); | ||||||
|
||||||
/// Sets the `CreationPriority` property. | ||||||
/// The `CreationPriority` property specifies the priority used during the WebView2 | ||||||
/// browser process creation. | ||||||
/// Set `CreationPriority` to `COREWEBVIEW2_CREATION_PRIORITY_NORMAL` will create the | ||||||
/// WebView2 browser process with normal priority. | ||||||
/// Set `CreationPriority` to `COREWEBVIEW2_CREATION_PRIORITY_HIGH` will attempt to | ||||||
/// create the WebView2 browser process with high priority. | ||||||
/// Default is `COREWEBVIEW2_CREATION_PRIORITY_HIGH`. | ||||||
/// Note that the host app's priority must be at least normal for | ||||||
/// `COREWEBVIEW2_CREATION_PRIORITY_HIGH` to be applied. Otherwise the WebView2 browser | ||||||
/// process still get created with normal priority even with `COREWEBVIEW2_CREATION_PRIORITY_HIGH` | ||||||
/// setting. Additionally, currently `CreationPriority` only applies to the creation of the | ||||||
/// WebView2 browser process. `CreationPriority` may be broadened to apply to other parts of | ||||||
/// WebView2 creation in the future. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can also update this note to suggest how we could change this in the future.
Suggested change
|
||||||
// MSOWNERS: wangsongjin@microsoft.com | ||||||
[propput] HRESULT CreationPriority([in] COREWEBVIEW2_CREATION_PRIORITY creationPriority); | ||||||
} | ||||||
``` | ||||||
## WinRT and .NET | ||||||
```c# | ||||||
namespace Microsoft.Web.WebView2.Core | ||||||
{ | ||||||
enum CoreWebView2CreationPriority | ||||||
{ | ||||||
Normal = 0, | ||||||
High = 1, | ||||||
}; | ||||||
|
||||||
runtimeclass CoreWebView2EnvironmentOptions | ||||||
{ | ||||||
|
||||||
// ... | ||||||
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2EnvironmentOptions3")] | ||||||
{ | ||||||
|
||||||
CoreWebView2CreationPriority CreationPriority { get; set; }; | ||||||
|
||||||
} | ||||||
} | ||||||
} | ||||||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talking to @LiangTheDev we should move CreationPriority to the CoreWebView2Environment. In the future we may want to support changing the priority during creation.