1

Debugging offline HTML

From Resco's Wiki
Jump to navigation Jump to search
Resco JavaScript Bridge

When creating and testing custom HTML pages and scripts, it is often necessary to debug the JavaScript code to see what is actually happening. You can use alerts and logging as a substitute for this option, but in general, debugging gives you much quicker insight into the actual execution.

Depending on the platform you are working on, there are different ways how to enable debugging. This document describes the approaches for Windows, Android, and iOS.

Resco Mobile CRM JSDev edition

We offer a development/debugging version of Resco Mobile CRM app: https://github.com/Resconet/JSBridge/tree/master/MobileCRM

This version of the app opens a port for JavaScript debugger and allows the HTML root overriding.

Warning Don't use in production!

Windows Desktop/Store

Windows Desktop app uses two different browser controls for hosting iframes – Default Chromium browser and obsolete Internet Explorer which isn’t supported anymore and it’s available only for background compatibility.

Debugging the Windows Desktop app using Chromium browser

  1. In the app, navigate to the iframe that you want to debug.
  2. Open Google Chrome.
  3. In the address bar, go to localhost and add a debugger port:

This requires using the JSDev edition of Mobile CRM app. MSI installation is available at JSBridge GitHub.

Debugging the store app (Windows 10) webview using Microsoft Edge DevTools Preview

  1. Install and launch Microsoft Edge DevTools Preview (free app available from the Microsoft Store).
  2. Start Resco Mobile CRM and navigate to a form that uses iframes.
  3. In the DevTools, click the debug target that you want to debug.

Edge devtools debugging

Debugging the store app (Windows 10) with Edge WebView2

In v15.2 we introduced an alternative to the legacy WebView. Edge WebView2 browser can be activated in Woodford configuration. The production versions of Resco mobile apps don’t support debugging this browser by default for security reasons. Developers must use the JSDev edition of the Mobile CRM app which supports debugging. MSIXBundle installation is available at JSBridge GitHub.

Debugging can be activated by classic right-click + Inspect or (e.g., in case of hidden iframe) it can be initiated directly from your JavaScript code by executing the command MobileCRM.bridge.command("openDevTools");

Both methods open a standalone window with Edge Inspector bound to inspected iframe.

Android

Android supports debugging of the web pages opened in third-party applications by using a remotely attached Chrome inspector.

Mobile CRM application doesn’t support debugging by default for security reasons. However, it’s possible to switch it on by calling the method “enableDebug” from your Offline HTML solution. See following link for details: https://www.resco.net/javascript-bridge-reference/#MobileCRM_Bridge_enableDebug

Developers can use the JSDev edition of the Mobile CRM app which supports debugging by default. It’s available at: https://github.com/Resconet/JSBridge/tree/master/MobileCRM

In addition to the enabled debugger, this edition supports the Offline HTML overriding (see below).

To learn more about Android remote debugging, take a look at the Google tutorial: https://developer.chrome.com/docs/devtools/remote-debugging/

iOS

iOS also supports debugging of the web pages opened in third-party applications. However, apps from the AppStore (or even from the TestFlight) live in the sandbox which prevents development tools connecting to them. That’s why we started to provide the special installation that can be used for development purpose. It’s available at

https://github.com/Resconet/JSBridge/tree/master/MobileCRM

Installing Debug Build on iOS Simulator

To install the debug build on iOS Simulator follow these steps:

  1. Open Xcode menu: Xcode / Open Developer Tool / iOS Simulator
  2. Open Terminal, go to iPhoneSimulator directory and type following command:
xcrun simctl install booted MobileCrm.app

Installing Debug Build on iPhone/iPad

To install the debug (JSDev) build follow these steps:

  1. Create iOS Developer account at https://developer.apple.com
  2. Create a Wildcard App ID for bundle ID “*” (Identifiers / App IDs)
  3. Create an iOS app development provisioning profile for this AppID and download it (as Wildcard.mobileprovision file)
  4. Log in to your account from Xcode (Preferences / Accounts)
  5. Create an iOS Development signing identity (View Details button)
  6. Download iResign tool from https://www.resco.net/downloads/iReSign.app.zip
  7. Unzip it and run it
  8. Provide the path to IPA (from this folder), path to Wildcard.mobileprovision file and choose your development signing identity
  9. Specifying custom entitlement is not recommended. Leave that box empty. Entitlements are taken from your provisioning profile automatically.
  10. Changing the bundle ID is optional. Rather leave that box unchecked
  11. Resign the IPA and deploy it via iTunes or Xcode/Devices.
  12. If it didn’t work, make sure that device was included in your provisioning profile.

Preparing the debugging environment

Debugging on iOS (both device and Simulator) is performed by using Safari WebInspector on the Mac. We recommend using the latest version of Safari or at least the version corresponding to Safari version on your device.

To enable remote debugging you will need to enable the WebInspector in Safari settings (option “Advanced”).

Debugging on iOS 1

Then enable the “Develop” menu in Safari preferences (tab Advanced) on Mac.

Debugging on iOS 2

Now you can connect your iPad via USB, open the client application and navigate to the form showing your offline HTML. After that you should observe the submenu “iPad” under Safari Develop menu showing the client application and HTML file opened on its form.

Debugging on iOS 3

Click on it to connect WebInspector.

Debugging on iOS 4

Hint If Safari is still missing the iPad option, try to quit it and restart once more.

Change local copy of offline HTML files

The typical development cycle for Offline HTML development is as follows:

  1. Change the local copy of the Offline HTML solution.
  2. Upload changed files to Woodford.
  3. Publish Woodford mobile project.
  4. Synchronize client app to get new customization.
  5. Verify the changes.

This can be frustrating and time-consuming. Fortunately, there are some shortcuts that can save a vital portion of the development/testing time.

One of the shortcuts is the possibility of changing the local copy of the Offline HTML files, which is possible on iOS Simulator and Windows platforms. Offline HTML reside in the WWW subfolder of the app data.

In case of Windows 7 Desktop application, the application data are stored in the following folder: %APPDATA%\MobileCRM

which is typically: C:\Users\{UserName}\AppData\Roaming\MobileCRM

In case of Windows Store (Win10), it’s %LOCALAPPDATA%\Packages\Resco.MobileCRM_{StoreId}\LocalState\MobileCRM

which is typically: C:\Users\{UserName}\AppData\Local\Packages\ Resco.MobileCRM_{StoreId}\LocalState\MobileCRM

In case of iOS Simulator, app files are also applied to the file system at: ~/Library/Developer/CoreSimulator/Devices/{SimulatorID}/data/Containers/Data/Application

To find the right application within this folder, try to search for a specific file (like JSBridge.js) inside this root.

To find the SimulatorId of the currently booted simulator, open the Terminal app and insert the following command: xcrun simctl list | grep Booted

Override offline HTML root

Another shortcut that can save a lot of development time is overriding the offline HTML root. Once you installed the JSDev edition of our app from Debug Builds (see above), the app handles a special URL that can change the root from which it takes the offline HTML files.

First, place your offline HTML solution on a local or remote HTTP server that's reachable from testing the device. It can be any type of server (for example, IIS or Apache), but we recommend using Visual Studio Typescript project which automatically starts the IIS Express instance with your offline HTML files. We provide a template for an empty offline HTML solution here:

https://www.resco.net/downloads/OfflineHtml.zip

To make the IIS Express available from the local network, specify your IP address as the target URL instead of “localhost” and use the following command to reveal the URL: netsh http add urlacl url=http://10.211.55.5:4199/ user=everyone

When a local copy of offline HTML solution is available via HTTP, follow these steps to override the root:

  1. Go back to your iOS/Android device or simulator.
  2. Open Mobile CRM JSDev edition app and minimize it – let it run on background.
  3. Open the web browser (Safari/Chrome) and type the following URL:
    mobilecrm:// htmlRoot?set=http://{IP Address}:{Port}

Your mobile app should be brought up from the background and display a message that the offline HTML root was changed. From this moment, the app should take all offline HTML files from your HTTP server instead of local app storage.

If you prefer command-line tools instead of typing the URL to browser, use the following ADB command for Android:

adb shell am start -a android.intent.action.VIEW -d mobilecrm://htmlRoot?set=http://{IP Address}:{Port}

or this one for iOS Simulator:

xcrun simctl openurl booted mobilecrm://htmlRoot?set=http://{IP Address}:{Port}

Override root (alternative method)

There's an alternative way of overriding the root directory of offline HTML files for the JSDev edition of the app. Go to the app installation folder and start the app with a special command line option:

start MobileCrm.exe -htmlRoot {IP Address}:{Port} 
start MobileCrm.exe -htmlRoot http://localhost:{Port}




Was this information helpful? How can we improve?