GithubHelp home page GithubHelp logo

plugin.hybridwebview's People

Contributors

candidodmv avatar gerricom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

plugin.hybridwebview's Issues

NullReferenceException in HybridWebViewNavigationDelegate.DidFinishNavigation

I've experienced a NRE in HybridWebViewNavigationDelegate.DidFinishNavigation on an iPhone 8 (iOS 14.2) recently. Unfortunately it gives not much more information than the stack trace below. Any help or hint is highly welcome.

HybridWebViewNavigationDelegate.DidFinishNavigation (WebKit.WKWebView webView, WebKit.WKNavigation navigation)
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state)
NSAsyncSynchronizationContextDispatcher.Apply ()
(wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate)
UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName)
Application.Main (System.String[] args)

NullReferenceException when XAML Hot Reload (and other cases)

Hi,

I'm experiencing Null Reference exceptions, at least when the XAML Hot Reload is executed in a page where a Plugin.HibridWebView is located.

Steps to reproduce:

  1. Have a XAML page with a Plugin.HybridWebView
  2. Activarte XAML Hot Reload for Xamarin.Forms
  3. Debug the app to a device
  4. Make a change in the XAML and save. Hot Reload is executed

expected: Hot Reload is executed without any crash

current: app crashes because of a null reference exception in the HybridWebView dll.

Stack trace:

at Plugin.HybridWebView.Droid.HybridWebViewRenderer+<>c__DisplayClass34_0.<SetCurrentUrl>b__0 () [0x00016] in <2f2d06da51e84164a0ac7ab59cb79a28>:0 at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <d706cf8faf5542949900cf6d57864528>:0 at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <d706cf8faf5542949900cf6d57864528>:0 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.30(intptr,intptr)

Note: this is just one way that I know for sure makes the plugin crash but it's a more generic issue not really related to the Hot Reload itself, I think. I got this null reference exceptions in other scenarios I can't easily reproduce and explain right now.

Cannot access a disposed object: Android.Webkit.WebView

Steps to reproduce:

  1. Have 3+ ContentViews each with a HibridWebViewControl component
  2. Add some buttons to change the content views in the page to navigate through the webviews
  3. Navigate fast from contentView1 to contentView3 to show the last webview passing over the others.

expected: last webview is shown, no crashes

current:

Cannot access a disposed object.
Object name: 'Android.Webkit.WebView'.
at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <26521a5118b44c858c385715922b9d5d>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <26521a5118b44c858c385715922b9d5d>:0
at Android.Webkit.WebView.get_Url () [0x0000a] in <4ccdb3137d974856b786e1aeebbfbab6>:0
at Plugin.HybridWebView.Droid.HybridWebViewRenderer.b__35_0 () [0x0000c] in <2f2d06da51e84164a0ac7ab59cb79a28>:0
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <4ccdb3137d974856b786e1aeebbfbab6>:0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <4ccdb3137d974856b786e1aeebbfbab6>:0
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.44(intptr,intptr)

I use the webview in an own VideoPlayer component to reproduce video:

public sealed class VideoPlayer : Grid, IDisposable
{
    private HybridWebViewControl _webPlayer;


    public static readonly BindableProperty VideoUrlProperty = BindableProperty.Create(nameof(VideoUrl), typeof(Uri), typeof(VideoPlayer), null, BindingMode.TwoWay);
    

    public Uri VideoUrl
    {
        get => (Uri) GetValue(VideoUrlProperty);
        set => SetValue(VideoUrlProperty, value);
    }

    public static readonly BindableProperty AutoPlayProperty = BindableProperty.Create(nameof(AutoPlay), typeof(bool), typeof(VideoPlayer), false, BindingMode.TwoWay);

    public bool AutoPlay
    {
        get => (bool)GetValue(AutoPlayProperty);
        set => SetValue(AutoPlayProperty, value);
    }

    public static readonly BindableProperty VideoLoadedCommandProperty = BindableProperty.Create(nameof(VideoLoadedCommand), typeof(ICommand), typeof(VideoPlayer));
    public ICommand VideoLoadedCommand
    {
        get => (ICommand)GetValue(VideoLoadedCommandProperty);
        set => SetValue(VideoLoadedCommandProperty, value);
    }

    public VideoPlayer()
    {
        _webPlayer = new HybridWebViewControl
        {
            BackgroundColor = Color.Transparent,
            VerticalOptions = LayoutOptions.FillAndExpand,
            HorizontalOptions = LayoutOptions.FillAndExpand
        };
        Children.Add(_webPlayer);

        _webPlayer.OnNavigationCompleted += WebPlayer_Navigated;

        VideoLoadedCommand = new Command(OnVideoLoaded);
    }

    public void OnVideoLoaded()
    {
        if (AutoPlay)
        {
            Play();
        }
    }

    public void Play()
    {
        _webPlayer.InjectJavascriptAsync("document.getElementsByTagName('video')[0].play();");
    }

    public void Pause()
    {
        _webPlayer.InjectJavascriptAsync("document.getElementsByTagName('video')[0].pause();");
    }

    private void WebPlayer_Navigated(object sender, string e)
    {
        _webPlayer.InjectJavascriptAsync(@"document.getElementsByTagName('video')[0].pause();
                    document.getElementsByTagName('video')[0].style.backgroundColor='transparent';
                    document.getElementsByTagName('video')[0].style.width='100%';
                    document.getElementsByTagName('body')[0].style.backgroundColor='transparent';");

        VideoLoadedCommand?.Execute(null);
    }

    public void OpenVideo(object sender = null, EventArgs e = null)
    {
        Children.Remove(_webPlayer);
        Children.Add(_webPlayer);

        _webPlayer.Source = VideoUrl.AbsoluteUri;
        _webPlayer.HorizontalOptions = LayoutOptions.FillAndExpand;
        _webPlayer.VerticalOptions = LayoutOptions.FillAndExpand;
    }

    public void CloseVideo(object sender = null, EventArgs e = null)
    {
        Dispose();
    }

    public void Dispose()
    {
        try
        {
            _webPlayer.OnNavigationCompleted -= WebPlayer_Navigated;
            Children.Clear();                
            _webPlayer?.Dispose();
            _webPlayer = null;                
        }
        catch (Exception exception)
        {
            Debug.WriteLine(exception.Message+exception.StackTrace);
        }
    }
}

Maybe the solution proposed here can be helpful:

xamarin/Xamarin.Forms#6286

Android: NullReferenceException when returning form far away tab

Steps to reproduce:

  1. Create a Xamarin.Forms app with a TabbedPage as MainPage.
  2. Create 5 tabs
  3. Place the HybridWebView on the first tab with StringData as source
  4. Start the app on Android. Navigate to the fifth tab and back to the first
  5. get following exception:

Object reference not set to an instance of an object.
at Plugin.HybridWebView.Droid.HybridWebViewRenderer+<>c__DisplayClass34_0.b__0 () [0x00016] in :0
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <55654ebe9f2a48e6bade2862bb243f94>:0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <55654ebe9f2a48e6bade2862bb243f94>:0
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr)

I guess this is because Android disposes my WebView when I'm far away from the first tab. Then this function is called and because I don't have an URI it throws the exception.
But it's just a guess as I had not the time yet to test it with your sample code.

Is there a way to download a file from a website?

On my website I have some files that can be downloaded. These files are retuned as octet-stream. The native browsers like chrome, edge, etc. can download these files. Is it possible to download these files inside a WebView?

Performance on Android

Hello @candidodmv ,

firstly thx for your fork, nice work.

We use this in our Xamarin Forms project.
I have a question related to the Android performance.
I figured out that the performance on Android is much lower than on iOS.

Are there some tips or tricks to improve the performance on Android side?
Maybe with a customer renderer or something like that?

Thx Stefan

Sanity check

Just a quick sanity check. My project needs to add Apple Pay/Google Pay. Our payment processor only offers a hosted payment control. Our working assumption is that we would host their control in an iFrame and use HybridWebView to interact with the plugin. The Xamarin app will need notifications that the payment was processed (order complete) and handle any errors returned. Is that a good use of this control? Note that the iFrame will be Next.js code. And we are well aware that Apple and Android do not have WebView2 supported (unlike UWP) so this js function will not work window.external.notify(message);.

Cookies not working if set too early

If you call SetCookieAsync right after the control is constructed the cookie is not set, as the internal OnSetCookieRequestedAsync-event is not yet initialized.
I also did not see a way to detect this state externally to wait for it...

Maybe the cookies could be implemented with a CookieContainer and sync them on demand like in the original WebView?

I did call SetCookieAsync in the Appearing-event of my page and about 4 out of 5 times the control is not ready at that stage.

[Xamarin.iOS] Deprecated API Usage UIWebView

Hello @candidodmv ,

Apple flaged the use of UIWebview as deprecated some time ago. You will get this warning when you upload the build to the Apple Store.

There is now already a prerelease of Forms where this is refactored to WKWebView: xamarin/Xamarin.Forms#7323

This will effect also this library in near future when apple let us not upload new apps on the 04.2020 and blocks also app updates after 12.2020.
My question is now if you plan to refactor also this library to be working again when the official stable Forms release is available?

Thx Stefan

Path Collision

warning: the following paths have collided (e.g. case-sensitive paths
on a case-insensitive filesystem) and only one from the same
colliding group is in the working tree:

'HybridWebView/MacOS/HybridWebViewRenderer.cs'
'HybridWebView/macOS/HybridWebViewRenderer.cs'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.