Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-27056

iOS: WebView HTML JS code can no longer access "Titanium." API (but "Ti." exists) as of 8.0.0

    Details

    • Story Points:
      2
    • Sprint:
      2019 Sprint 11, 2019 Sprint 12

      Description

      Summary:
      The Titanium object is undefined within a WebView's HTML <script/> as of 8.0.0.
      Only the Ti object is defined.

      Steps to reproduce:

      1. Set up a Classic Titanium "app.js" with the below code.
      2. Build and run on iOS with Titanium 8.0.0 or 8.0.1.
      3. Observe the log.

      var htmlText =
      		'<!DOCTYPE html>\n' +
      		'<html>\n' +
      		'	<head>\n' +
      		'		<meta name="viewport" content="width=device-width, initial-scale=1.0">\n' +
      		'	</head>\n' +
      		'	<body>\n' +
      		'		<p>HTML JavaScript Titanium API Test</p>\n' +
      		'	</body>\n' +
      		'	<script>\n' +
      		'		document.addEventListener("DOMContentLoaded", function(e) {\n' +
      		'			Ti.API.info("@@@ Logging via Ti.API.info() method.");\n' +
      		'			Titanium.API.info("@@@ Logging via Titanium.API.info() method.");\n' +
      		'			Ti.App.fireEvent("app:requestLogMessage", {\n' +
      		'				message: "@@@ Fired event via Ti.App.fireEvent() method",\n' +
      		'			});\n' +
      		'			Titanium.App.fireEvent("app:requestLogMessage", {\n' +
      		'				message: "@@@ Fired event via Titanium.App.fireEvent() method",\n' +
      		'			});\n' +
      		'			Ti.App.addEventListener("app:signalHtml", function eventHandler() {\n' +
      		'				Ti.API.info("@@@ Received event via Ti.App.addEventListener() method.");\n' +
      		'				Ti.App.removeEventListener("app:signalHtml", eventHandler);\n' +
      		'			});\n' +
      		'			Titanium.App.addEventListener("app:signalHtml", function eventHandler() {\n' +
      		'				Titanium.API.info("@@@ Received event via Titanium.App.addEventListener() method.");\n' +
      		'				Titanium.App.removeEventListener("app:signalHtml", eventHandler);\n' +
      		'			});\n' +
      		'			Ti.App.fireEvent("app:webViewReady", {})\n' +
      		'		});\n' +
      		'	</script>\n' +
      		'</html>\n';
       
      Ti.App.addEventListener("app:requestLogMessage", function(e) {
      	Ti.API.info(e.message);
      });
      Ti.App.addEventListener("app:webViewReady", function(e) {
      	Ti.App.fireEvent("app:signalHtml", {});
      });
       
      var window = Ti.UI.createWindow();
      var webView = Ti.UI.createWebView({
      	html: htmlText,
      });
      window.add(webView);
      window.open();
      

      Expected Result:
      The following should be logged. (You'll get the below with a 7.5.1 built app.)

      [INFO]  @@@ Logging via Ti.API.info() method.
      [INFO]  @@@ Logging via Titanium.API.info() method.
      [INFO]  @@@ Fired event via Ti.App.fireEvent() method
      [INFO]  @@@ Fired event via Titanium.App.fireEvent() method
      [INFO]  @@@ Received event via Ti.App.addEventListener() method.
      [INFO]  @@@ Received event via Titanium.App.addEventListener() method.
      

      Actual Result:
      Only the 1st message gets logged in Titanium 8.0.0 or 8.0.1 because the script errors out when using the Titanium object. (This is the bug.)

      [INFO]  @@@ Logging via Ti.API.info() method.
      

      Recommended Solution:
      Add a var Titanium = Ti; to the code that gets injected into the WKWebView here...
      TiUIWebView.m

      Work-Around:
      Use the Ti object instead of the Titanium object within the HTML's script.

        Attachments

          Activity

            People

            • Assignee:
              vijaysingh Vijay Singh
              Reporter:
              jquick Joshua Quick
              Reviewer:
              Jan Vennemann
              Tester:
              Keerthi Mahalingam (Inactive)
            • Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                  Git Source Code