Skip to content

Commit 9c0ea14

Browse files
API Spec: extended NewWindowRequested event
1 parent 63dbaa5 commit 9c0ea14

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Background
2+
WebView2 raises the `NewWindowRequested` event when a new window is opened. The WebView2 team has been asked to include the name of the new window
3+
being created as a parameter of `NewWindowRequestedEventArgs`. This window name is the name given to the window when it is opened
4+
using `window.open(url, windowName)`.
5+
6+
In this document we describe the updated API. We'd appreciate your feedback.
7+
8+
# Description
9+
We propose extending the `NewWindowRequestedEventArgs` to provide access to the `Name` property.
10+
The `Name` property will return the name of the new window being created.
11+
12+
# Examples
13+
## C++: Get name of window
14+
15+
``` cpp
16+
wil::com_ptr<ICoreWebView2> m_webviewEventSource;
17+
EventRegistrationToken m_newWindowRequestedToken = {};
18+
19+
m_webviewEventSource->add_NewWindowRequested(
20+
Callback<ICoreWebView2NewWindowRequestedEventHandler>(
21+
[this](ICoreWebView2* sender, ICoreWebView2NewWindowRequestedEventArgs* args)
22+
-> HRESULT {
23+
wil::com_ptr<ICoreWebView2NewWindowRequestedEventArgs2> args2;
24+
25+
if(SUCCEEDED(args->QueryInterface(IID_PPV_ARGS(&args2)))) {
26+
wil::unique_cotaskmem_string name;
27+
CHECK_FAILURE(args2->get_Name(&name));
28+
}
29+
30+
return S_OK;
31+
})
32+
.Get(),
33+
&m_newWindowRequestedToken);
34+
```
35+
36+
## C#: Get name of window
37+
```c#
38+
webView.CoreWebView2.NewWindowRequested += WebView_NewWindowRequested;
39+
40+
void WebView_NewWindowRequested(object sender, CoreWebView2NewWindowRequestedEventArgs e)
41+
{
42+
string newWindowName = e.Name;
43+
MessageBox.Show(this, newWindowName);
44+
}
45+
```
46+
47+
# API Details
48+
## C++
49+
```
50+
/// This is a continuation of the `ICoreWebView2NewWindowRequestedEventArgs` interface.
51+
[uuid(9bcea956-6e1f-43bc-bf02-0a360d73717b), object, pointer_default(unique)]
52+
interface ICoreWebView2NewWindowRequestedEventArgs2 : ICoreWebView2NewWindowRequestedEventArgs {
53+
/// Gets the name of the new window.
54+
[propget] HRESULT Name([out, retval] LPWSTR* name);
55+
}
56+
```
57+
58+
## C#
59+
```c#
60+
namespace Microsoft.Web.WebView2.Core
61+
{
62+
runtimeclass CoreWebView2NewWindowRequestedEventArgs
63+
{
64+
// The following properties already exist in the CoreWebView2NewWindowRequestedEventArgs
65+
// ICoreWebView2NewWindowRequestedEventArgs members
66+
// String Uri { get; };
67+
// CoreWebView2 NewWindow { get; set; };
68+
// Boolean Handled { get; set; };
69+
// Boolean IsUserInitiated { get; };
70+
// CoreWebView2WindowFeatures WindowFeatures { get; };
71+
72+
String Name { get; };
73+
74+
// The following already exists in the CoreWebView2NewWindowRequestedEventArgs
75+
// Windows.Foundation.Deferral GetDeferral();
76+
}
77+
}
78+
```

0 commit comments

Comments
 (0)