devsmadeofsteel / plugin.hybridwebview Goto Github PK
View Code? Open in Web Editor NEWXamarin Plugin for a HybridWebView
License: Other
Xamarin Plugin for a HybridWebView
License: Other
Hello @candidodmv ,
Sorry for spamming your Git repo but we found a bug when we call the method ClearCookiesAsync() on iOS.
Xamarin Version: 4.3.0.991211
iOS: 13.1.3
Greetings
Stefan
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)
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:
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.
Steps to reproduce:
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:
Steps to reproduce:
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.
It would be great to have the option to not only replace the user-agent, but to also append/prepend to it.
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?
Is there any way to clear cache?
I used AddLocalCallback to regist JS callback function. In uwp, it works fine, js call the C# code through registed function successfully . But the same code don't work in Android 10 (targetSdkVersion="29").
Maybe same as : xamarin/Xamarin.Forms#1376
I'm trying to open a remote address with a pdf file, instead of a page.
Is there a way to show the pdf contents from a server file?
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
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);.
It would be great if this plugin could support .NET MAUI running with WinUI (targeting `net6.0-windows10.0.19041.0`).
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.
based on this
SKLn-Rad/Xam.Plugin.Webview@27ac0d6
Hello @candidodmv,
I know we can call C# code from js using this library. Is there a way to call JS Function from C#?
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
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'
First of all thank you for forking and improving this library! This is way easier to have callbacks than default one!
About input=file, unfortunately for some reason it does not work at all with Android :(
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.