Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25163] WebView html property always return null on Android

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionCannot Reproduce
Resolution Date2019-07-01T17:17:20.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, webview
ReporterRio Diep
AssigneeUnknown
Created2017-08-09T00:41:55.000+0000
Updated2019-07-01T17:17:20.000+0000

Description

When loading a local html file using webview. Html attribute always return null even the content is populated successfully on the screen. Sample: (tested with SDK 6.1.1.GA, 6.1.2.GA) * index.xml*
<Alloy>
	<Window id="win" modal="true">
		<WebView id="webview" url="/test.html" />
	</Window>
</Alloy>
* index.js*
$.win.open();
$.webview.addEventListener('load', function(e) {
 
	setTimeout(function() {
		Ti.API.info($.webview.html);
	}, 100);
 
});
It's linked to AC-5118 ticket as i didn't describe clearly in previous ticket therefore it was closed.

Attachments

FileDateSize
Untitled.png2017-08-09T23:06:17.000+0000124929
Untitled.png2017-08-09T04:25:36.000+000063358

Comments

  1. Motiur Rahman 2017-08-09

    Hello [~rdiep], I tested your test code with my test.html file and I could not reproduce this issue. It does not return the null value. Actually getHtml( ) method returns the value of the html property. - http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.WebView-method-getHtml Testing Environment 1. Ti SDK 6.1.1.GA, 6.1.2.GA 2. Android Emulator v6, 7 Output
       [INFO] :   HTML TEXT=<html lang="en"><head><script id="__ti_injection">
       [INFO] :   
       [INFO] :   if(!this.JSON){JSON={};}
       [INFO] :   (function(){function f(n){return n<10?'0'+n:n;}
       [INFO] :   if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return this.getUTCFullYear()+'-'+
       [INFO] :   f(this.getUTCMonth()+1)+'-'+
       [INFO] :   f(this.getUTCDate())+'T'+
       [INFO] :   f(this.getUTCHours())+':'+
       [INFO] :   f(this.getUTCMinutes())+':'+
       
    Thanks
  2. Rio Diep 2017-08-09

    Hi [~morahman] I tested with Genymotions and it always return undefined not only for html property but also other properties. Attached is the log *bulk-bill.xml*
       <Alloy>
               <Window title="" id="bulkBill" theme="Theme.Noactionbar">
           	        <WebView id="bulkBillView" url="/bulkBill.html"></WebView>
               </Window>
       </Alloy>
       
    *bulk-bill.js*
       $.bulkBill.open();
       $.bulkBillView.addEventListener("load", function() {
           Alloy.Globals.log('Webview Object');
           Alloy.Globals.log($.bulkBillView);
       });
       
    !Untitled.png|thumbnail!
  3. Motiur Rahman 2017-08-09

    Hello [~rdiep], Use this Ti.API.info($. bulkBillView.getHtml()); Instead of Alloy.Globals.log($.bulkBillView); Thanks
  4. Rio Diep 2017-08-09

    Hi [~morahman] Attached is the log using Ti.API.info($.bulkBillView.getHtml()); Thank you. !Untitled.png|thumbnail!
  5. Motiur Rahman 2017-08-10

    Hi [~rdiep], I see the value from your image which returns getHtml() method. What is your expected behavior? Thanks
  6. Rio Diep 2017-08-10

    Hi [~morahman] As i want to get the html content and replace some of the context dynamically from .js file. However, it returns undefined so i couldn't do it. In v.5.2.2.GA and 5.5.1.GA, i'm able to obtain the html content but not on sdk v6 Thanks.
  7. Motiur Rahman 2017-08-10

    Hello [~rdiep], I tested with the Ti SDK 5.5.1.GA and 6.1.2.GA and get the same output result as like this
       [INFO] :   HTML TEXT=<html lang="en"><head><script id="__ti_injection">
       [INFO] :   
       [INFO] :   if(!this.JSON){JSON={};}
       [INFO] :   (function(){function f(n){return n<10?'0'+n:n;}
       [INFO] :   if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return this.getUTCFullYear()+'-'+
       [INFO] :   f(this.getUTCMonth()+1)+'-'+
       [INFO] :   f(this.getUTCDate())+'T'+
       [INFO] :   f(this.getUTCHours())+':'+
       [INFO] :   f(this.getUTCMinutes())+':'+
       [INFO] :   f(this.getUTCSeconds())+'Z';};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};}
       [INFO] :   var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';}
       [INFO] :   function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);}
       [INFO] :   if(typeof rep==='function'){value=rep.call(holder,key,value);}
       [INFO] :   switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';}
       [INFO] :   gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';}
       [INFO] :   v=partial.length===0?'[]':gap?'[\n'+gap+
       [INFO] :   partial.join(',\n'+gap)+'\n'+
       [INFO] :   mind+']':'['+partial.join(',')+']';gap=mind;return v;}
       [INFO] :   if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}
       [INFO] :   v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+
       [INFO] :   mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}}
       [INFO] :   if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;}
       [INFO] :   rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}
       [INFO] :   return str('',{'':value});};}
       [INFO] :   if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}}
       [INFO] :   return reviver.call(holder,key,value);}
       [INFO] :   cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+
       [INFO] :   ('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
       [INFO] :   if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;}
       [INFO] :   throw new SyntaxError('JSON.parse');};}}());
       [INFO] :   
       [INFO] :   var Ti={_event_listeners:[],createEventListener:function(b){b={listener:b,systemId:-1,index:this._event_listeners.length};this._event_listeners.push(b);return b},getEventListenerByKey:function(b,c){for(var a=0;a<this._event_listeners.length;a++)if(this._event_listeners[a][b]==c)return this._event_listeners[a];return null},API:TiAPI,App:{addEventListener:function(b,c){var a=Ti.createEventListener(c);a.systemId=TiApp.addEventListener(b,a.index);return a.systemId},removeEventListener:function(b,c){if("number"==
       [INFO] :   typeof c){TiApp.removeEventListener(b,c);var a=Ti.getEventListenerByKey("systemId",c);null!==a&&Ti._event_listeners.splice(a.index,1)}e
       [INFO] :   Choreographer: Skipped 42 frames!  The application may be doing too much work on its main thread.
       [INFO] :   APSAnalyticsService: Analytics Service Started
       [INFO] :   APSAnalyticsService: Stopping Analytics Service
       
       
    Thanks
  8. Rio Diep 2017-08-10

    Hi [~morahman] I think the function getHtml() itself is the same but the actual html property is undefined. Have you tried Ti.API.log($.bulkBillView.html) ? As you seen in my previous attachment when i tried to log the $.bulkBillView object, it shows html and other properties as undefined. Thanks
  9. Motiur Rahman 2017-08-12

    Hello! Yes, the getHtml() method return the same value as html. But the latest Ti SDK getHtml() returns the "url" property value and "html" returns html property value only. Hope this helps.
  10. Rio Diep 2017-08-13

    Hi [~morahman] Yeah I got it. But the "html" return undefined in my case, not the html property value. Therefore i cannot get the html content of the file. Thanks.
  11. Motiur Rahman 2017-08-14

    Hello! Since getHtml() method returns the same value to the latest Ti SDK so you can use that. I don't see any issue with that method. if you set html property to the webview like [this ](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.WebView-property-html) Now you can call it
        $.win.open();
        
        $.webview.addEventListener('load', function(e) {
        
        	setTimeout(function() {
        		Ti.API.info("HTML TEXT=" + $.webview.html);
        	}, 100);
        
        });
        
    Thanks
  12. Rio Diep 2017-08-14

    Hi Due to long content of the html file, I don't think it's a good practice to put the whole html content into the html property in xml file. Could you please try with the code below and log to see what will you get for the html property? *test.html*
        <html><head></head><body>hello</body></html>
        
    *index.xml*
        <Alloy>
        	<Window id="win" modal="true">
        		<WebView id="webview" url="/test.html" />
        	</Window>
        </Alloy>
        
    *index.js*
        $.win.open();
        $.webview.addEventListener('load', function(e) {
         
        	setTimeout(function() {
        		Ti.API.log($.webview.html);
        	}, 100);
         
        });
        
  13. Motiur Rahman 2017-08-14

    Hello! It returns undefined value so I said you before alternatively you can use getHtml() method. And I will forward it to our engineering team for the undefined value. Thanks
  14. Gary Mathews 2017-10-31

    This works fine on 6.2.2.GA
        var win = Ti.UI.createWindow({backgroundColor: 'gray'}),
            webView = Ti.UI.createWebView({
                url: '/test.html'
            });
        
        webView.addEventListener('load', function(e) {
            alert(webView.html);
        });
        
        win.add(webView);
        win.open();
        
  15. Alan Hutton 2019-07-01

    Unable to reproduce under 8.0.2.GA.

JSON Source