Skip to content

Commit 7be3af7

Browse files
committed
added a file for the get favicon api
1 parent 623787d commit 7be3af7

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

specs/GetFavicon.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Background
2+
A Favicon is an asset which is a part of every webpage, and typically displayed on each tab. Developers would
3+
like to have an API which allows them to retrieve the Favicon of a webpage, as well as get an update whenever
4+
the favicon has changed.
5+
6+
# Description
7+
We propose a new Webview2 event which would allow developers to get access to the current Favicon of a page,
8+
as well as be notified when the favicon changes.
9+
10+
# Examples
11+
## Win32 C++ Registering a listener for favicon changes
12+
```cpp
13+
CHECK_FAILURE(m_webView->add_FaviconChanged(
14+
Microsoft::WRL::Callback<ICoreWebView2FaviconUpdateEventHandler>(
15+
[this](ICoreWebView2* sender, IUnknown* args) -> HRESULT
16+
{
17+
18+
LPWSTR value;
19+
CHECK_FAILURE(sender->get_FaviconUrl(&value));
20+
21+
22+
return S_OK;
23+
}
24+
).Get(),
25+
&m_faviconChangedToken));
26+
```
27+
## .NET / WinRT Registering a listener for favicon changes
28+
```c#
29+
webView.CoreWebView2.FaviconChanged += (CoreWebView2 sender, Object arg) =>
30+
{
31+
string value = sender.faviconUrl;
32+
33+
};
34+
```
35+
# API Notes
36+
See [API Details](#api-details) Section below for API reference
37+
# API Details
38+
## Win32 C++
39+
```cpp
40+
/// Interface for the Favicon changed event handler
41+
[uuid(A0CDE626-8E5E-4EE2-9766-58F3696978FE), object, pointer_default(unique)]
42+
interface ICoreWebView2FaviconChangedEventHandler : IUnknown {
43+
/// Called to provide the implementer with the event args for the
44+
/// corresponding event.
45+
HRESULT Invoke(
46+
[in] ICoreWebView2* sender,
47+
[in] IUnknown* args);
48+
}
49+
50+
[uuid(DC838C64-F64B-4DC7-98EC-0992108E2157), object, pointer_default(unique)]
51+
interface ICoreWebView2_5 : ICoreWebView2_4 {
52+
/// Add an event handler for the `FaviconChanged` event.
53+
/// `FaviconChanged` runs when the WebView favicon changes
54+
HRESULT add_FaviconChanged(
55+
[in] ICoreWebView2FaviconChangedEventHandler* eventHandler,
56+
[out] EventRegistrationToken* token);
57+
58+
/// Removing the event handler for `FaviconChanged` event
59+
HRESULT remove_FaviconChanged(
60+
[in] EventRegistrationToken token);
61+
62+
/// used to access the current value of the favicon
63+
[propget] HRESULT FaviconUrl([out, retval] LPWSTR* value);
64+
}
65+
```
66+
67+
## .Net/ WinRT
68+
```c#
69+
namespace Microsoft.Web.WebView2.Core {
70+
71+
/// Interface for the Favicon changed event handler
72+
runtimeclass CoreWebView2 {
73+
event Windows.Foundation.TypedEventHandler<CoreWebView2, Object> FaviconChanged;
74+
string FaviconUrl {get;};
75+
}
76+
}
77+
```

0 commit comments

Comments
 (0)