While there is still a legitimate bug present, we were able to find a temporary workaround:
// This JS snippet helps to avoid the WebView focus trap issue with the SeparateProcess execution mode. It listens for the Tab keypress (on <B>) and suppresses that event while asking window to give up the focus. Normally this is intercepted by the app, but due to the bug in WWAHost, it gets interpreted as normal keyboard Tab in this mode. This approach does NOT work when the focus is within the iframe due to Cross-Origin security requirements
public static async Task<string> AddTabHandler(this WebView webView)
{
if (webView == null)
{
return null;
}
// Even though we are suppressing the key event, there is a chance of race with other logic (typically handing outline styles). As a workaround (and given Tab button will always give up the focus), hide all of the outlines for consistency
await webView.AddStyleAsync("* { outline: 0 !important; }");
var focusHandlerJs = "document.addEventListener('keydown', function(e) { if (e.keyCode == 9) { e.preventDefault(); e.stopPropagation(); window.departFocus('up', { originLeft: 0, originTop: 0, originWidth: 0, originHeight: 0 }); } }, true);";
return await webView.ExecuteAsync(focusHandlerJs);
}
public static async Task<string> ExecuteAsync(this WebView webView, string js)
{
if (webView == null || string.IsNullOrEmpty(js))
{
return null;
}
return await webView.InvokeScriptAsync("eval", new string[] { js });
}
public static async Task<string> AddStyleAsync(this WebView webView, string css)
{
if (webView == null || string.IsNullOrEmpty(css))
{
return null;
}
var injectStyleJs =
$"var css = '{css}';" +
"var style = document.createElement('style');" +
"document.head.appendChild(style);" +
"style.type = 'text/css';" +
"style.appendChild(document.createTextNode(css));";
return await webView.ExecuteAsync(injectStyleJs);
}