[TIMOB-26855] Windows: Add "baseURL" support to WebView.setHtml()
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2019-04-29T17:56:39.000+0000 |
Affected Version/s | Release 6.0.3 |
Fix Version/s | Release 8.1.0 |
Components | Windows |
Labels | parity, url, webview |
Reporter | Joshua Quick |
Assignee | Kota Iguchi |
Created | 2019-02-24T13:04:21.000+0000 |
Updated | 2019-04-29T17:56:39.000+0000 |
Description
*Summary:*
Titanium currently documents that the
WebView.setHtml()
method supports a 2nd argument on Android and iOS which can provide a "baseURL" setting. Android used to support this, but it was inadvertently removed in Titanium 6.0.3. This feature should be re-added since it's needed by "iframes" to indicate which URL an iframe's embedded paths are relative to.
For example, a YouTube video embedded within an iframe will not play on Android or iOS unless a "baseURL" of "https://www.youtube.com" is provided.
*Steps to reproduce:*
Build and run the below code on Android.
Tap on the video to attempt to play it.
Notice that the video won't play. Instead it reads "Video Unavailable".
Build and run on iOS.
Tap on the video play it.
Notice that the video plays fine. _(This is because the "baseURL" is being used.)_
var htmlText =
'<!DOCTYPE html>' +
'<html>' +
' <body>' +
' <iframe width="560" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen/>' +
' </body>' +
'</html>';
var window = Ti.UI.createWindow();
var webView = Ti.UI.createWebView();
//webView.html = htmlText;
webView.setHtml(htmlText, { baseURL: "https://www.youtube.com" });
window.add(webView);
window.open();
*Work-Around:*
The "baseURL" is not needed if the webpage was loaded from the Internet (ie: the "url" property). That is, "baseURL" is only applicable when loading HTML from string. So, hosting the webpage on your own web server will work-around this problem.
https://github.com/appcelerator/titanium_mobile_windows/pull/1369
FR Passed, waiting on Jenkins build.
Merged to master.
Verified the fix on SDK 8.1.0.v20190426222341.Video plays as expected. Works fine .closing