maui icon indicating copy to clipboard operation
maui copied to clipboard

[ios] HtmlWebViewSource.BaseUrl is applied with an unexpected prefix

Open dodikk opened this issue 7 months ago • 5 comments

Description

Setting HtmlWebViewSource.BaseUrl results in different window.location.href on iOS and Android respectively.

  • Android ==> BaseUrl is applied as is
  • iOS ==> some file://...<appBundle>.../... prefix is mixed with BaseUrl value which breaks some of the page content.

ACTUAL RESULT (from debug alert() javascript logs)

Android: Screenshot 2024-01-09 at 19 56 24

iOS: Screenshot 2024-01-09 at 19 58 09

EXPECTED RESULT window.location.href is equal to HtmlWebViewSource.BaseUrl on both platforms

Steps to Reproduce

private static string BaseUrlForCaptcha => "https://identity-dev.coinpaymints.com";

// then in ctor() of ContentView
{
    PlainWebviewHtmlSource.BaseUrl = BaseUrlForCaptcha;
    PlainWebviewHtmlSource.Html = pageContentsHtml;
}

// then in onload() in pageContentsHtml
alert(window.location.href);

Link to public reproduction project repository

https://github.com/dodikk/bug-maui-webview-baseurl

Version with bug

7.0.101

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

No response

Did you find any workaround?

No workaround found

So an important sign-up (aka "register") flow of my app is broken.

Relevant log output

No response

dodikk avatar Jan 09 '24 18:01 dodikk

Hi @dodikk. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar Jan 09 '24 19:01 ghost

Here is a minimal sample link as requested https://github.com/dodikk/bug-maui-webview-baseurl

dodikk avatar Jan 09 '24 20:01 dodikk

The native WKWebView of iOS sdk shows the baseUrl as expected. So it seems like MAUI is modifying it under the hood for some reason. So please add a flag to disable that behaviour when needed.

Screenshot 2024-01-10 at 15 10 31

[upd] same results for the UIWebView native control

p.s. the native sample is in the same repository https://github.com/dodikk/bug-maui-webview-baseurl

dodikk avatar Jan 10 '24 13:01 dodikk

Seems like NSBundle.MainBundle.BundlePath is concatenated with the value provided by me.

However, i am unable to find that in maui codebase https://github.com/search?q=repo%3Adotnet%2Fmaui+%22NSBundle.MainBundle.BundlePath%22&type=code

dodikk avatar Jan 10 '24 16:01 dodikk

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

ghost avatar Jan 11 '24 19:01 ghost

Verified this on Visual Studio Enterprise 17.9.0 Preview 5(8.0.3). Repro on iOS 17.2 and MacCatalyst with below Project: BaseUrlBugDemo.zip

XamlTest avatar Feb 06 '24 09:02 XamlTest

Something of sorts happening for us in iOS: in our case we load local file.

We set BaseUrl like this:

image

And it does not work properly because we get a Trailing Slash added in the output. Output of window.location.href:

file:///private/var/containers/Bundle/Application/-App Guid-/-Package Unique Name-/Content/index.html/ (note that slash after html)

I've done a test to get rid of that extra slash and then the page works:

image

I don't know why that Trailing Slash is being added automatically. The following code works fine (for Android):

image

P.S.: If anyone landed here and was trying to load local files, this will do:

image

image

IsvAdvanced avatar Apr 04 '24 11:04 IsvAdvanced

@IsvAdvanced thanks for your info. The trailing slash does happen for me as well (as you can see on the attached screenshots). However, that is not breaking my case.

dodikk avatar Apr 04 '24 11:04 dodikk

@IsvAdvanced Unfortunately that does not answer my question since I have a slightly different situation. What I am trying to achieve is

  1. opening a local file in webView
  2. while having the baseUrl of the website front-end
  3. in order to let the user interact with re-captcha

That does indeed work for me on

  1. on android.
  2. with native WKWebView of iOS (both swiftlang and C#)

So this ticket has been created for MS team to implement the same behavior for MAUI WebView.

dodikk avatar Apr 04 '24 11:04 dodikk

@IsvAdvanced if you want that trailing slash fixed by MS team, it might be a good idea to create a separate ticket (like this one). Separate ticket seems to make sense since that slash is a different problem.

p.s. it is appended by native WKWebView, so it seems like little can be done to fix that. So you might be forced to stick with your workaround unfortunately.

dodikk avatar Apr 04 '24 11:04 dodikk

@IsvAdvanced if you want that trailing slash fixed by MS team, it might be a good idea to create a separate ticket (like this one). Separate ticket seems to make sense since that slash is a different problem.

p.s. it is appended by native WKWebView, so it seems like little can be done to fix that. So you might be forced to stick with your workaround unfortunately.

The issue could very well be the same: I think the point for us both is that what we set in BaseUrl should be respected.

We got this behaviour after migrating to MAUI from Xamarin (there it worked fine).

IsvAdvanced avatar Apr 04 '24 12:04 IsvAdvanced

I think the point for us both is that what we set in BaseUrl should be respected.

@IsvAdvanced well, yes and no. I view these as two special cases of the same "should be respected" ideal. Different symptoms, different root causes, etc.

dodikk avatar Apr 04 '24 13:04 dodikk

We got this behaviour after migrating to MAUI from Xamarin (there it worked fine).

@IsvAdvanced "trailing slash working fine under x.forms" - might be due to x.forms using a deprecated UIWebView rather than WKWebView or newer iOS webView controls.

p.s. thanks for boosting this issue activity. No much action from MS unfortunately.

dodikk avatar Apr 04 '24 13:04 dodikk

As a Workaround we finally solved this issue with a custom handler and a custom view, the problem is here where the local Path is added image

We have added a custom handler on IOS with a custom view and removed the dir constructor image and the custom view Overriding the OpenHtml method image Hope this helps

smeagol75 avatar Jul 16 '24 08:07 smeagol75

@smeagol75 thanks for the workaround. If that's a change not within maui framework but rather in my sample code - could you please send a PullRequest to that repository? https://github.com/dodikk/bug-maui-webview-baseurl

Or please share a link to your PR if you have already done so. (For some reason i do not see it so far) Thanks in advance.

dodikk avatar Jul 16 '24 11:07 dodikk

@smeagol75 in case your fix and workaround are within maui framework... could you please explain how to update my visualstudio or workflows (to which beta/nightly/etc) so that the changes would take effect on my sample and my main app. Thanks again.

dodikk avatar Jul 16 '24 11:07 dodikk

@smeagol75 so can we please have your code as text rather than merely as screenshots? Thanks again for the reply.

dodikk avatar Jul 25 '24 16:07 dodikk

Ok, i guess, I've managed to apply the workaround and it seems to work ok.

  • commit: a73ef05b07c03cb3f52fe992f91e99c89b29d0ea
  • repo: https://github.com/dodikk/bug-maui-webview-baseurl

https://github.com/dodikk/bug-maui-webview-baseurl/tree/a73ef05b07c03cb3f52fe992f91e99c89b29d0ea

dodikk avatar Jul 25 '24 17:07 dodikk