maui
maui copied to clipboard
[ios] HtmlWebViewSource.BaseUrl is applied with an unexpected prefix
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:
iOS:
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
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.
Here is a minimal sample link as requested https://github.com/dodikk/bug-maui-webview-baseurl
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.
[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
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
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.
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
Something of sorts happening for us in iOS: in our case we load local file.
We set BaseUrl like this:
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:
I don't know why that Trailing Slash is being added automatically. The following code works fine (for Android):
P.S.: If anyone landed here and was trying to load local files, this will do:
@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.
@IsvAdvanced Unfortunately that does not answer my question since I have a slightly different situation. What I am trying to achieve is
- opening a local file in webView
- while having the baseUrl of the website front-end
- in order to let the user interact with re-captcha
That does indeed work for me on
- on android.
- 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.
@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.
@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).
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.
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.
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
We have added a custom handler on IOS with a custom view and removed the dir constructor
and the custom view Overriding the OpenHtml method
Hope this helps
@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.
@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.
@smeagol75 so can we please have your code as text rather than merely as screenshots? Thanks again for the reply.
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