Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,19 @@ private void OnDelegateOnDecidePolicyNavigation(object? _, WKNavigationDelegate.

private async void OnDelegateOnDidFinishNavigation(object? sender, EventArgs args)
{
_ = await InvokeScript(WebViewHelper.BuildWebKitInvokeCSharpActionScript(_scriptHandlerMessageName, stringify: true));
try
{
_ = await InvokeScript(WebViewHelper.BuildWebKitInvokeCSharpActionScript(_scriptHandlerMessageName, stringify: true));
}
catch (JavaScriptException)
{
// The just-finished navigation didn't load a scriptable HTML document (e.g. a file
// download, image, or PDF response) - EvaluateJavaScriptAsync then fails at the
Comment on lines +304 to +305

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should try to detect common document types on which script cannot be executed.

And log error/warning when this "script invoke" failed. There might be situations, when this script call is expected, but exception would be silently ignored after this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please write a more concise code comment, with more natural line breaks.
The longer comment the less people will actually read it in the future.

// native WebKit level and InvokeScript surfaces that as a JavaScriptException. That
// failure is not fatal on its own: the C#<->JS bridge simply isn't available for this
// particular navigation. Left unguarded, this exception previously escaped this
// async void event handler uncaught and crashed the whole process.
}

using var url = _webView.Url;
NavigationCompleted?.Invoke(this, new WebViewNavigationCompletedEventArgs { Request = Uri.TryCreate(url!.AbsoluteString, UriKind.Absolute, out var uri) ? uri : null, IsSuccess = true });
Expand Down