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

iOS: webview.html is null when loading an external URL #13887

Open
1 task done
m1ga opened this issue Jul 27, 2023 · 4 comments
Open
1 task done

iOS: webview.html is null when loading an external URL #13887

m1ga opened this issue Jul 27, 2023 · 4 comments
Labels
bug ios needs triage This issue hasn't been reviewed by maintainers

Comments

@m1ga
Copy link
Contributor

m1ga commented Jul 27, 2023

I have searched and made sure there are no existing issues for the issue I am filing

  • I have searched the existing issues

Description

Opening an URL in a WebView and trying to get the HTML code only works on Android:

var win = Ti.UI.createWindow();
var www = Ti.UI.createWebView({
	url: "https://www.google.com/"
});
www.addEventListener("load", function() {
	console.log(www.html)
})
win.add(www);
win.open();

Expected Behavior

it should load google and then return the HTML code.

Actual behavior

it will return "null"

Workaround

use

www.addEventListener("load", function(e) {
	www.evalJS("document.documentElement.outerHTML.toString()", function(e) {
		console.log(e);
	});
})

that is the code that Android will run:

return ((TiUIWebView) view).getJSValue("document.documentElement.outerHTML");

Platform

iOS

SDK version you are using

12.2.0

Alloy version you are using

No response

@m1ga m1ga added bug needs triage This issue hasn't been reviewed by maintainers labels Jul 27, 2023
@m1ga m1ga added the ios label Oct 1, 2023
@hansemannn
Copy link
Collaborator

iOS does not download the HTML for remote URLs. This was discussed a few times in the past, but always decided to not be done internally, as the HTML can change at any time, so the developer should decide when to fetch it.

@m1ga
Copy link
Contributor Author

m1ga commented Oct 7, 2023

The Android version fetches it on the fly for you too. As shown above it just runs document.documentElement.outerHTML inside the webview.
So for parity it would be nice if it would do the same on iOS instead of returning NULL and you have to run evalJS with the same code. It would just be very convenient if the getter runs it for you (if it is null).

@hansemannn
Copy link
Collaborator

I would actually not want this to happen on iOS (and actually also not on Android) as it adds additional memory overhead and computing resources for a functionality that nearly no one uses (fetching remote html when setting an url). The evalJS API has been made exactly for that use case, so if developers need to access the current rendered HTML, thats the way to go. Thats also how it's handled natively.

But: If this is an issue that affects many developers and causes a lot of struggle, we can expose it. I just don't see that urge right now, but am open for dicussions.

@m1ga
Copy link
Contributor Author

m1ga commented Oct 7, 2023

at the moment it was only one community request so far. So we'll keep it as an open issue for now. I've added the example to the docs: #13932 so people can use that for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ios needs triage This issue hasn't been reviewed by maintainers
Projects
None yet
Development

No branches or pull requests

2 participants