-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HybridWebViewHandler "VirtualView cannot be null here" #26883
Comments
Hi @jfversluis, I am not able to create repro for that. My company product is not open source, but i can tell you that, this problem shows sometimes when naviagate back from view with TradingView. I created workaround for this problem: public partial class CustomHybridWebViewHandler
{
protected override WKWebView CreatePlatformView()
{
var configOrigin = base.CreatePlatformView().Configuration;
var config = new WKWebViewConfiguration();
if (OperatingSystem.IsMacCatalystVersionAtLeast(10) || OperatingSystem.IsIOSVersionAtLeast(10))
{
config.AllowsPictureInPictureMediaPlayback = true;
config.AllowsInlineMediaPlayback = true;
config.MediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypes.None;
}
config.DefaultWebpagePreferences!.AllowsContentJavaScript = true;
config.UserContentController = configOrigin.UserContentController;
config.SetUrlSchemeHandler(new SchemeHandler(this, configOrigin.GetUrlSchemeHandler("app")!), "app");
var webview = new MauiHybridWebView(this, RectangleF.Empty, config)
{
BackgroundColor = UIColor.Clear,
AutosizesSubviews = true
};
return webview;
}
private class SchemeHandler : NSObject, IWKUrlSchemeHandler
{
private readonly IWKUrlSchemeHandler _originalHandler;
private readonly HybridWebViewHandler _webViewHandler;
public SchemeHandler(HybridWebViewHandler webViewHandler, IWKUrlSchemeHandler originalHandler)
{
_originalHandler = originalHandler;
_webViewHandler = webViewHandler;
}
[Export("webView:startURLSchemeTask:")]
[SupportedOSPlatform("ios11.0")]
public void StartUrlSchemeTask(WKWebView webView, IWKUrlSchemeTask urlSchemeTask)
{
try
{
var _ = _webViewHandler.VirtualView;
}
catch (InvalidOperationException e)
{
return; //ignore
}
_originalHandler.StartUrlSchemeTask(webView, urlSchemeTask);
}
[Export("webView:stopURLSchemeTask:")]
public void StopUrlSchemeTask(WKWebView webView, IWKUrlSchemeTask urlSchemeTask)
{
}
}
} |
I understand that you can't just share your whole application, that is also not what a reproduction is. Please create a minimal project with just enough of your code to show the issue. That will greatly increase the changes of diagnosing what might be going on and fixing it. Additionally a lot of times this exercise helps developers detect a fix or workaround themselves. |
@jfversluis here you have PR #26928 :) |
I commented on the PR with something that you mentioned before, but for this issue to happen, the hybrid view will have to have been collected/detached. Are you calling DisconnectHandler in your code at all? Are you using some community toolkit and/or nuget that may be doing this for you? @jfversluis @PureWeen what is the best way to debug this? An idea that I think may work is creating a custom handler and overriding the DisconnectHandler method? Maybe this is part of some popup and or page that is being navigated away in a stack? @michalpobuta Maybe you can describe a possible navigation flow that this happens in? You may be able to repro if you create some part of the navigation flow and have a hybrid webview control with a dummy html page that just keeps requesting some data. Then when you navigate around you can repro. The only reason the VirtualView would be null would be:
Another test you can try is to add the Your PR will prevent the crash, but you should first determine who is disposing the view while it is still running. |
Hi @mattleibow, I don't use any DisconnectHandler in my code. I am 99% sure, that this happens because of executing js code while page is not anymore on stack. This is because i have TradingView on my page, and I am using This isn't any popup page, this is regular page based on ContentPage. I could try with |
Description
In my app, during executing js code, when I go back from web view, sometimes I get this error.
Steps to Reproduce
To hard to reproduce, but change that line:
to that:
should help
Link to public reproduction project repository
No response
Version with bug
9.0.21 SR2.1
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
all iOS
Did you find any workaround?
nope
Relevant log output
The text was updated successfully, but these errors were encountered: