Skip to content

Commit

Permalink
Merge branch 'main' into victorhuangwq/updatetemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
victorhuangwq committed Sep 29, 2023
2 parents 312d1be + dbf21fb commit 07e9c39
Show file tree
Hide file tree
Showing 7 changed files with 324 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ jobs:
ado_project: 'Edge'
ado_area_path: 'Edge\Web Experience\WebView2'
ado_tags: 'WV2_GitHub'
ado_gh_closed_tag: 'WV2_GitHub_Closed'
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
# WebView2 Feedback
# Microsoft Edge WebView2

A place for developers to report feedback or search existing issues for [Microsoft Edge WebView2 control](https://aka.ms/webview). Open an [issue](https://github.com/MicrosoftEdge/WebViewFeedback/issues/new) to submit a feature request or bug report. Any "feature request" or "bug" that has the "tracked" label added means that we are also tracking the issue on our internal backlog.
Welcome to Microsoft Edge WebView2 feedback repository.

To get the latest news, API proposals, and SDK Release announcements, please subscribe to the [WebView2Announcements](https://github.com/MicrosoftEdge/WebView2Announcements) repo!
This is a place for all developers of the [Microsoft Edge WebView2](https://aka.ms/webview) to report bugs, make feature requests, and ask questions and have discussions about WebView2.

Tips or Best Practices from other WebView2 devs use the ["Tips" label](https://github.com/MicrosoftEdge/WebView2Feedback/labels/Tip%21).
- 🐞 [How to report a bug](#🐞-how-to-report-a-bug)
- 💡 [How to request a feature](#💡-how-to-request-a-feature)
-[Ask a question about WebView2](https://github.com/MicrosoftEdge/WebView2Feedback/discussions/new?category=q-a)
- 💬 [Discuss WebView2 with other developers](https://github.com/MicrosoftEdge/WebView2Feedback/discussions)
- 📣 [Subscribe to WebView2Announcements for news, API proposals and SDK Release announcements](https://github.com/MicrosoftEdge/WebView2Announcements)
- 📖 [Read the WebView2 documentation](https://aka.ms/webview)


### 🐞 How to report a bug

1. [Search for existing open bugs](https://github.com/MicrosoftEdge/WebView2Feedback/issues?q=is%3Aissue+is%3Aopen+label%3Abug) to avoid duplicates.
1. If you find that your bug is already reported, give it a 👍 reaction, and add a comment with additional details that may help us investigate.
1. If the issue is not already reported, [open a new issue](https://github.com/MicrosoftEdge/WebView2Feedback/issues/new/choose).
1. Tracked issues will be labeled with the `tracked` label. If you see this label, we are aware of the issue and tracking it on our internal backlog.

### 💡 How to request a feature

1. [Search for existing feature request](https://github.com/MicrosoftEdge/WebView2Feedback/issues?q=is%3Aissue+is%3Aopen+label%3A%22feature+request%22) to avoid duplicates.
1. If you find a similar feature request, give it a 👍 reaction, and provide additional context into how you would use the feature.
2. If the feature is not already requested, [open a new issue](https://github.com/MicrosoftEdge/WebView2Feedback/issues/new/choose).
1. Tracked issues will be labeled with the `tracked` label. If you see this label, we are aware of the issue and tracking it on our internal backlog.

## Code of Conduct
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
3 changes: 2 additions & 1 deletion diagnostics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ This folder contains directions for gathering various detailed diagnostics/logs
- [ETW Trace](etw.md): Event Tracing for Windows (ETW) traces include detailed events on system state and the activities WV2 was doing before and when an issue occurs.
- [Installer Logs](install.md): Installer logs include information about any errors that WV2's installer/updater hit when trying to install or update the WV2 runtime.
- [GPU Info](gpu.md): GPU logs include details on the user's GPU and any potential graphics or rendering issues.
- [Network Logs](network.md): Network logs include the network requests, responses, and details on any errors when loading files.
- [Network Logs](network.md): Network logs include the network requests, responses, and details on any errors when loading files.
- [Code Integrity](code_integrity.md): how to root cause STATUS_INVALID_IMAGE_HASH errors.
28 changes: 28 additions & 0 deletions diagnostics/code_integrity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Code Integrity in WebView2

## Why it is important
Code integrity is a feature of Windows that verifies the authenticity and integrity of the code that runs on your system. It helps protect your system from malware, tampering, and unauthorized changes. Code integrity checks the digital signatures of the files that are loaded into memory, and prevents any file that does not have a valid signature from running in webview2.

## Symptoms
Child process failed with kind COREWEBVIEW2_PROCESS_FAILED_KIND_RENDER_PROCESS_EXITED
and exit code -1073740760 or STATUS_INVALID_IMAGE_HASH.

Users may see error page in the WebView2:

![Compatibility problem](compatibility_problem.png)

## Identify the dll

**Compatibility problem** web page may show the culprit file otherwise use Event Viewer.

Open Event Viewer by typing eventvwr in the search box on the taskbar and selecting the app.

- In the left pane, expand Windows Logs and click on System.
- In the right pane, click on Filter Current Log.
- In the Filter tab, under Event sources, select Microsoft-Windows-CodeIntegrity and click on OK.
- You will see a list of events related to code integrity – search for the ones with msedgewebview2.exe process.
- The file name and path of the file that caused the code integrity violation are shown in the message.




Binary file added diagnostics/compatibility_problem.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
129 changes: 129 additions & 0 deletions specs/AllowHostInputProcessing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Background
WebView2 .NET developers often encounter issues where certain default events are not raised in the WebView2 .NET control.

This issue occurs because user inputs are directly delivered to the browser, and the host application does not receive the corresponding messages.

This causes some default event handling API of .NET control not to work, such as PreProcessMessage and ProcessCmdKey in WinForms.

It also prevents some keys from reaching Key Event realated APIs such as OnKeyDown and ToolStripMenuItem.

In order to solve this type of issue, we provide an api which allows user inputs pass through the browser to the host app.

# Description
`AllowHostInputProcessing` allows user input messages(keyboard, mouse, touch, and pen) to pass through the browser window to be received by an app process window.

The messages can be received by Win32 API ::GetMessage() or ::PeekMessage(). This provides the host app a chance to handle the message before dispatching to the WebView2 HWND.

If the host app does not handle input, it is forwarded to the browser process on the user's behalf. This API does not introduce any requirement for the developer to forward all input as is the case with visual hosting. This API should not be used with visual hosting, and has no effect when using CreateCoreWebView2CompositionControllerWithOptions to create the controller.

Setting `AllowHostInputProcessing` to `TRUE` makes `AcceleratorKeyPressed`(all platforms) and `OnKeyDown`(WinForms only) event asynchronous.

# Examples
## Win32 C++
```cpp
// We assume WebView2 is hosted in a MFC application. CMFCApplicationApp is a CWinApp.
// This function can not be triggered by default when focus is in WebView.
// It can be triggered by setting 'AllowHostInputProcessing' to true.
BOOL CMFCApplicationApp::PreTranslateMessage(MSG* pMsg) {
if (pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP ||
pMsg->message == WM_SYSKEYDOWN || pMsg->message == WM_SYSKEYUP && webview_has_focus_)
// Prehandle the message. The message will not be sent to WebView if return TRUE.
return HandleMsgBeforeWebView(pMsg);
return FALSE;
}

// Create a ControllerOptions and set 'AllowHostInputProcessing' to TRUE.
HRESULT CreateControllerWithInputPassthrough()
{
auto webViewEnvironment10 = m_webViewEnvironment.try_query<ICoreWebView2Environment10>();
if (!webViewEnvironment10)
{
FeatureNotAvailable();
return S_OK;
}

wil::com_ptr<ICoreWebView2ControllerOptions> options;
CHECK_FAILURE(webViewEnvironment4->CreateCoreWebView2ControllerOptions(options.GetAddressOf()));

wil::com_ptr<ICoreWebView2ControllerOptions3> webView2ControllerOptions3;
if (SUCCEEDED(options->QueryInterface(IID_PPV_ARGS(&webView2ControllerOptions3))))
{
CHECK_FAILURE(webView2ControllerOptions3->put_AllowHostInputProcessing(TRUE));
}

CHECK_FAILURE(webViewEnvironment10->CreateCoreWebView2ControllerWithOptions(
m_mainWindow, options.get(),
Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
this, &AppWindow::OnCreateCoreWebView2ControllerCompleted)
.Get()));

return S_OK;
}
```
### .NET, WinRT
```c#
partial class BrowserForm
{
// This function can not be triggered by default when focus is in WebView.
// It can be triggered by setting 'AllowHostInputProcessing' to true.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
//DoSomething();
return base.ProcessCmdKey(ref msg, keyData);
}
// ...
private Microsoft.Web.WebView2.WinForms.WebView2 webView2Control;
}
CoreWebView2Environment _webViewEnvironment;
public CreateWebView2Controller(IntPtr parentWindow)
{
CoreWebView2ControllerOptions controllerOptions = _webViewEnvironment.CreateCoreWebView2ControllerOptions();
controllerOptions.AllowHostInputProcessing = true;
CoreWebView2Controller controller = null;
controller = await _webViewEnvironment.CreateCoreWebView2ControllerAsync(parentWindow, controllerOptions);
//...
}
```

# API Details
## Win32 C++
```IDL
interface ICoreWebView2ControllerOptions3;
interface ICoreWebView2ControllerOptions3 : IUnknown {
/// `AllowHostInputProcessing` property is to enable/disable input passing through
/// the app before being delivered to the WebView2. This property is only applicable
/// to controllers created with `CoreWebView2Environment.CreateCoreWebView2ControllerAsync` and not
/// composition controllers created with `CoreWebView2Environment.CreateCoreWebView2CompositionControllerAsync`.
/// By default the value is `FALSE`.
[propget] HRESULT AllowHostInputProcessing([out, retval] BOOL* value);
/// Sets the `AllowHostInputProcessing` property.
/// Setting this property has no effect when using visual hosting.
[propput] HRESULT AllowHostInputProcessing([in] BOOL value);
}
```

## .NET, WinRT
```c#
namespace Microsoft.Web.WebView2.Core
{
runtimeclass CoreWebView2ControllerOptions;
runtimeclass CoreWebView2Environment;
runtimeclass CoreWebView2;
runtimeclass CoreWebView2Profile;

runtimeclass CoreWebView2ControllerOptions
{
// ...
Boolean AllowHostInputProcessing { get; set; };
}
}
```
139 changes: 139 additions & 0 deletions specs/NewWindowSourceFrameInfo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
Source Frame Info for New Window Requested
===

# Background
Currently there is no way to determine the source frame of a new window request. This information
can be useful when deciding how to open the content. For example, you may want to open requests
that originate in a 3rd party frame in the default browser instead of in a new WebView. The
WebView2 team is extending `NewWindowRequestedEventArgs` with an `OriginalSourceFrameInfo` property
to make this easier. Here we described the updated API.

# Examples
## OriginalSourceFrameInfo on NewWindowRequestedEventArgs
```c#
// Register a handler for the NewWindowRequested event.
// This handler will check the source frame info to determine how to open the
// request. Depending on the source frame URI, it will provide a new app window
// or open using the default browser.
webView.CoreWebView2.NewWindowRequested += delegate (
object webView, CoreWebView2NewWindowRequestedEventArgs args)
{
// The host can decide how to open based on source frame info,
// such as URI. For example, if the source is a 3rd party frame, open using
// the default browser.
bool useDefaultBrowser = IsThirdPartySource(
args.OriginalSourceFrameInfo.Source);
if (useDefaultBrowser)
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = args.OriginalSourceFrameInfo.Source,
// Open the URI in the default browser.
UseShellExecute = true
};
Process.Start(startInfo);
args.Handled = true;
}
else
{
CoreWebView2Deferral deferral = args.GetDeferral();
MainWindow main_window = new MainWindow(
webView.CreationProperties, args.Uri);
main_window.OnWebViewFirstInitialized = () =>
{
using (deferral)
{
args.Handled = true;
args.NewWindow = main_window.webView.CoreWebView2;
}
};
main_window.Show();
}
};
```
```cpp
// Register a handler for the NewWindowRequested event.
// This handler will check the source frame info to determine how to open the
// request. Depending on the source frame URI, it will provide a new app window
// or open using the default browser.
CHECK_FAILURE(m_webView->add_NewWindowRequested(
Callback<ICoreWebView2NewWindowRequestedEventHandler>(
[this](ICoreWebView2* sender, ICoreWebView2NewWindowRequestedEventArgs* args)
{
bool useDefaultBrowser = false;
Microsoft::WRL::ComPtr<ICoreWebView2NewWindowRequestedEventArgs3> args3;
if (SUCCEEDED(args->QueryInterface(IID_PPV_ARGS(&args3))))
{
Microsoft::WRL::ComPtr<ICoreWebView2FrameInfo> frame_info;
if (SUCCEEDED(args3->get_OriginalSourceFrameInfo(&frame_info))
&& frame_info)
{
// The host can decide how to open based on source frame info,
// such as URI. For example, if the source is a 3rd party frame,
// open using the default browser.
wil::unique_cotaskmem_string source;
CHECK_FAILURE(frame_info->get_Source(&source));
useDefaultBrowser = IsThirdPartySource(source.get());
}
}
if (useDefaultBrowser)
{
// Open the URI in the default browser.
ShellExecute(
nullptr, L"open", source.get(), nullptr, nullptr, SW_SHOWNORMAL);
CHECK_FAILURE(args->put_Handled(TRUE));
}
else
{
Microsoft::WRL::ComPtr<ICoreWebView2Deferral> deferral;
CHECK_FAILURE(args->GetDeferral(&deferral));
AppWindow* newAppWindow = new AppWindow(
m_creationModeId, GetWebViewOption(), L"none", m_userDataFolder,
false, nullptr, true, windowRect, !!shouldHaveToolbar);
newAppWindow->m_onWebViewFirstInitialized =
[args, deferral, newAppWindow]()
{
CHECK_FAILURE(args->put_NewWindow(newAppWindow->m_webView.get()));
CHECK_FAILURE(args->put_Handled(TRUE));
CHECK_FAILURE(deferral->Complete());
};
}
return S_OK;
})
.Get(),
nullptr));
```
# API Details
```
/// This is a continuation of the `ICoreWebView2NewWindowRequestedEventArgs` interface.
[uuid(92f08d94-70bd-4d2b-8332-18bd7d3b2b7c), object, pointer_default(unique)]
interface ICoreWebView2NewWindowRequestedEventArgs3 :
ICoreWebView2NewWindowRequestedEventArgs2 {
/// The frame info of the frame where the new window request originated. The
/// `OriginalSourceFrameInfo` is a snapshot of frame information at the time when the
/// new window was requested. See `ICoreWebView2FrameInfo` for details on frame
/// properties.
[propget] HRESULT OriginalSourceFrameInfo([out, retval] ICoreWebView2FrameInfo** frameInfo);
}
```
```c#
namespace Microsoft.Web.WebView2.Core
{
runtimeclass CoreWebView2NewWindowRequestedEventArgs
{
// ...
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2NewWindowRequestedEventArgs3")]
{
// The frame info of the frame where the new window request originated. The
// `OriginalSourceFrameInfo` is a snapshot of frame information at the time when the
// new window was requested. See `CoreWebView2FrameInfo` for details on frame
// properties.
CoreWebView2FrameInfo OriginalSourceFrameInfo { get; };
}
}
}
```

0 comments on commit 07e9c39

Please sign in to comment.