Debugging offline HTML
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 is available only for backward compatibility.
Debugging the Windows Desktop app using Chromium browser
- Use the JSDev edition of the Resco Mobile CRM app. MSI installation is available at JSBridge GitHub.
- In the app, navigate to the iframe that you want to debug.
- Open Google Chrome, MS Edge, or other Chromium-based browser on the same computer as app is running.
- Navigate to the following address:
http://localhost:9000
(for apps 15.0 or later)http://localhost:9222
(for apps 14.x or earlier)
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.
Important | Debugging WebView2 requires enabling the Developer Mode in Windows. See Microsoft documentation for details. |
The easiest way how to debug Offline HTML hosted in WebView2 is using the JSDev edition of the Mobile CRM app. 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. Warning: the debug window can appear behind the application window.
- Second method
Alternatively, you can use remote debugging, which also supports production versions of the Resco mobile app. The full instructions are available in Microsoft documentation; an abbreviated version is provided below:
- Enable the Developer Mode.
- Enable the Device Portal and create a portal account.
- Add the following variable to environment:
WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS --enable-features=msEdgeDevToolsWdpRemoteDebugging
. - In Microsoft Edge, go to the URL
edge://inspect#devices
. - Connect to remote device
http://localhost:50080
using your Device Portal credentials. - Click Inspect in the list of your iframes.
Debugging the store app (Windows 10) legacy webview using Microsoft Edge DevTools Preview
Warning | The legacy webview is being deprecated. |
- Install and launch Microsoft Edge DevTools Preview (free app available from the Microsoft Store).
- Start Resco Mobile CRM and navigate to a form that uses iframes.
- In the DevTools, click the debug target that you want to debug.
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 JSDev app on iOS Simulator
iOS Simulator is a part of the Xcode installation. It can be started either from the Xcode menu: Xcode > Open Developer Tool > iOS Simulator or directly from the Xcode installation package (folder /Applications/Xcode/Contents/Developer/Applications/Simulator.app).
To install the JSDev app on iOS Simulator, simply unzip the package MobileCRM_JSDev_ios_simulator_XY.zip from GitHub Releases and drag MobileCrm.app into the Simulator window. Alternatively, you can install it with following command:
xcrun simctl install booted MobileCrm.app
Installing JSDev app on iPhone/iPad
To install the debug (JSDev) build follow these steps:
- Create iOS Developer account at https://developer.apple.com
- Create a Wildcard App ID for bundle ID “*” (Identifiers / App IDs)
- Create an iOS app development provisioning profile for this AppID and download it (as Wildcard.mobileprovision file)
- Log in to your account from Xcode (Preferences / Accounts)
- Create an iOS Development signing identity (View Details button)
- Download iResign tool from https://www.resco.net/downloads/iReSign.app.zip
- Unzip it and run it
- Provide the path to IPA (from this folder), path to Wildcard.mobileprovision file and choose your development signing identity
- Specifying custom entitlement is not recommended. Leave that box empty. Entitlements are taken from your provisioning profile automatically.
- Changing the bundle ID is optional. Rather leave that box unchecked
- Resign the IPA and deploy it via iTunes or Xcode/Devices.
- 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”).
Then enable the “Develop” menu in Safari preferences (tab Advanced) on Mac.
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.
Click on it to connect WebInspector.
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:
- Change the local copy of the Offline HTML solution.
- Upload changed files to Woodford.
- Publish Woodford mobile project.
- Synchronize client app to get new customization.
- 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/{AppID}/Documents
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
Visit the JSBridge GitHub page. It contains samples that implement deploying distribution folder directly to Windows Desktop/Store and currently booted iOS Simulator via a single npm script: https://github.com/Resconet/JSBridge/tree/master/samples/common-pitfalls
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:
- Go back to your iOS/Android device or simulator.
- Open Mobile CRM JSDev edition app and minimize it – let it run on background.
- 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}