Skip to content
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

problems with onReceivedHttpAuthRequest when initialData is used #201

Closed
koskimas opened this issue Nov 29, 2019 · 5 comments
Closed

problems with onReceivedHttpAuthRequest when initialData is used #201

koskimas opened this issue Nov 29, 2019 · 5 comments

Comments

@koskimas
Copy link

koskimas commented Nov 29, 2019

Description

Hi,

first of all, thank you for adding yet another hugely useful feature: the onReceivedHttpAuthRequest hook 🥇

However, I seem to be having problems using it with initialData. I am able to open an initialUrl that is protected with basic auth (so our onReceivedHttpAuthRequest hook seems to work), but with initialData I'm getting the stack trace attached below. This happens on android, haven't tested iOS yet.

The initialData does have a baseUrl set, and it works just fine if we remove basic auth from a resource the initial page downloads. When we enable basic auth for the said resource and define the onReceivedHttpAuthRequest, we get the error.

Steps to reproduce

  1. Create a InAppWebView with any initialData that contains script or link tags that require basic authentication.
  2. Define a onReceivedHttpAuthRequest
  3. See an error being thrown from java code.

Stacktrace/Logcat

W/System.err(25396): java.net.MalformedURLException: unknown protocol: about
W/System.err(25396): 	at java.net.URL.<init>(URL.java:608)
W/System.err(25396): 	at java.net.URL.<init>(URL.java:498)
W/System.err(25396): 	at java.net.URL.<init>(URL.java:447)
W/System.err(25396): 	at com.pichillilorenzo.flutter_inappbrowser.InAppWebView.InAppWebViewClient.onReceivedHttpAuthRequest(InAppWebViewClient.java:263)
W/System.err(25396): 	at org.chromium.android_webview.AwContents.onReceivedHttpAuthRequest(PG:3)
W/System.err(25396): 	at android.os.MessageQueue.nativePollOnce(Native Method)
W/System.err(25396): 	at android.os.MessageQueue.next(MessageQueue.java:326)
W/System.err(25396): 	at android.os.Looper.loop(Looper.java:160)
W/System.err(25396): 	at android.app.ActivityThread.main(ActivityThread.java:6863)
W/System.err(25396): 	at java.lang.reflect.Method.invoke(Native Method)
W/System.err(25396): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
W/System.err(25396): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

I may be doing something horribly wrong though 😄 Please let me know if you need anything else from me.

Thanks for your help!

@koskimas
Copy link
Author

koskimas commented Nov 29, 2019

Some more information. So our initialData is a simple index.html page that has some script tags (in addition to some html code that's not included here).

    <link href="wp-content/themes/imt/vendor.css" rel="stylesheet" type="text/css"/>
    <link href="wp-content/themes/imt/style.css" rel="stylesheet" type="text/css"/>

    <script src="wp-content/themes/imt/js/vendor.js" type="text/javascript"></script>
    <script src="wp-content/themes/imt/js/vendor-untouched.js" type="text/javascript"></script>
    <script src="wp-content/themes/imt/js/templates.js" type="text/javascript"></script>
    <script src="wp-content/themes/imt/js/config.js" type="text/javascript"></script>
    <script src="wp-content/themes/imt/js/translations.js" type="text/javascript"></script>
    <script src="wp-content/themes/imt/js/scripts.js" type="text/javascript"></script>

The baseUrl we provide with the initialData requires basic authentication.

We seem to be getting the unknown protocol: about error even without onReceivedHttpAuthRequest defined. There also seems to be as many errors printed as there are link and script tags in our index.html. So it seems that somehow the protocol for these link and script tags' http auth challenges is about and the handling blows up.

@pichillilorenzo
Copy link
Owner

Can you post also error logs about:

There also seems to be as many errors printed as there are link and script tags in our index.html.

Thanks!
Maybe I found the solution: probably I need to update the InAppWebViewInitialData class and the loadData() method for Android adding the historyUrl parameter.(https://stackoverflow.com/a/51084539/4637638)

Can you test also on iOS please? Does it work or do you have the same errors like on Android?

@koskimas
Copy link
Author

koskimas commented Dec 2, 2019

All the printed errors are the same. We get the following error as many times as there are link and script tags in the index.html file:

W/System.err(25396): java.net.MalformedURLException: unknown protocol: about
W/System.err(25396): 	at java.net.URL.<init>(URL.java:608)
W/System.err(25396): 	at java.net.URL.<init>(URL.java:498)
W/System.err(25396): 	at java.net.URL.<init>(URL.java:447)
W/System.err(25396): 	at com.pichillilorenzo.flutter_inappbrowser.InAppWebView.InAppWebViewClient.onReceivedHttpAuthRequest(InAppWebViewClient.java:263)
W/System.err(25396): 	at org.chromium.android_webview.AwContents.onReceivedHttpAuthRequest(PG:3)
W/System.err(25396): 	at android.os.MessageQueue.nativePollOnce(Native Method)
W/System.err(25396): 	at android.os.MessageQueue.next(MessageQueue.java:326)
W/System.err(25396): 	at android.os.Looper.loop(Looper.java:160)
W/System.err(25396): 	at android.app.ActivityThread.main(ActivityThread.java:6863)
W/System.err(25396): 	at java.lang.reflect.Method.invoke(Native Method)
W/System.err(25396): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
W/System.err(25396): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

iOS seems to completely crash. All I'm getting is a "lost connection to device" message. This happens with and without the onReceivedHttpAuthRequest hook in place.

@pichillilorenzo
Copy link
Owner

For iOS, lauch it from Xcode and post the Xcode logs here please. Thanks!

@pichillilorenzo
Copy link
Owner

Now it should be fixed in the new version 2.1.0!

For Android, you need to set historyUrl parameter of InAppWebViewInitialData for initialData with the same value of baseUrl.

Instead, I tested the same thing on iOS but to me it works fine! Is your Xcode version >= 11?

This was referenced Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants