Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26848] Android: Re-add "baseURL" support to WebView.setHtml() that was removed in 6.0.3

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2019-04-23T21:38:52.000+0000
Affected Version/sRelease 6.0.3
Fix Version/sRelease 8.1.0
ComponentsAndroid
Labelsandroid, engArch, parity, url, webview
ReporterJoshua Quick
AssigneeJoshua Quick
Created2019-02-22T03:13:22.000+0000
Updated2019-04-23T21:38:52.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.

Comments

  1. Joshua Quick 2019-03-22

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/10795
  2. Lokesh Choudhary 2019-04-09

    FR Passed. Waiting for merge.
  3. Lokesh Choudhary 2019-04-16

    PR Merged.
  4. Keerthi Mahalingam 2019-04-23

    Verified the fix on SDK 8.1.0.v20190423074844.Video plays as expected. Closing .
        Name                        = Mac OS X
         Version                     = 10.13.6
         Architecture                = 64bit
       Node.js
         Node.js Version             = 8.9.1
         npm Version                 = 5.5.1
       Titanium CLI
         CLI Version                 = 5.1.1
       APPC CLI                       =7.0.11-70X.1
       Studio                         =5.1.2.201903111843
       Titanium SDK
         SDK Version                 = 8.1.0.v20190423074844
       Device                        = Oneplus 5T android 9,samsung s5 android 6
       Emulator.                     = pixel 2 xl android 8
       

JSON Source