- PhoneGap:Beginner's Guide(Third Edition)
- Purusothaman Ramanujam Giorgio Natili
- 489字
- 2021-07-16 13:22:30
Debugging workflow
The desktop browser is a great tool for hybrid mobile app development. The majority of your mobile development can be previewed and debugged in your desktop browser. Because PhoneGap leverages open web standards (HTML, CSS, and JavaScript), you can start work in a desktop browser and then move on to a native project once the functionality is fleshed out. This way, it's possible to speed up our development cycles and spend more time implementing core functionality. You can use the latest versions of any of the major desktop browsers such as Internet Explorer (IE), Google Chrome, Firefox, Safari, or Opera to get started with a PhoneGap app. All of these browsers have Developer Tools for logging and debugging your code.
New developers tend to prefer WebKit-based browsers; at the time of writing, Chrome has the largest install base market share followed by Firefox and Internet Explorer.
Note
Chrome also offers a technology known as Google Packaged Apps to build native apps based on web standards. More information about it is available at https://developer.chrome.com/apps/about_apps.
As you have seen, each browser offers different debugging tools and each tool has its pros and cons. Regardless of which tool you use, however, your debugging workflow is the same.
When investigating a specific problem, you will usually follow this process:
- Find the relevant code in the debugger's code view pane.
- Set breakpoint(s) where you think interesting things may occur.
- Run the script again by reloading the page in the browser if it's an inline script, or by clicking on a button if it's an event handler.
- Wait until the debugger pauses execution and makes it possible to step through the code.
- Investigate the values of variables. For example, look for variables that are undefined when they should contain a value, or return
false
when you expect them to returntrue
.
If necessary, you can use the console to evaluate code or change variables for testing. You can also execute complex JavaScript code and test a solution before implementing it.
Identifying the problem by learning which piece of code or input caused the error conditions and isolating it is a suitable approach. However, with mobile apps, things are not always so straightforward. The advantage of PhoneGap is that you can develop and debug in a common environment such as the browser, but keep in mind that a mobile app has to be tested and debugged on the target devices as well.
Although it's not a neat way of debugging, you can use console log messages to debug. These log messages will be printed in the console of the browser development tool. A sample use of the JavaScript code is provided here for reference:
console.log("Application running now");
There are several other debugging tools for PhoneGap/Cordova. While a few of them are free services, some of them are paid services:
- Ripple Emulator: http://emulate.phonegap.com/
- GapDebug: https://www.genuitec.com/products/gapdebug/
- jsHybugger: https://www.jshybugger.com/
- Weinre: http://people.apache.org/~pmuellr/weinre-docs/latest/
- Adobe Edge Inspect: https://creative.adobe.com/products/inspect
- Chrome: https://developer.chrome.com/devtools/docs/remote-debugging
- Boost程序庫完全開發指南:深入C++”準”標準庫(第5版)
- JavaScript全程指南
- C語言程序設計(第3版)
- LabVIEW程序設計基礎與應用
- CentOS 7 Linux Server Cookbook(Second Edition)
- Ext JS Data-driven Application Design
- Vue.js快跑:構建觸手可及的高性能Web應用
- FLL+WRO樂高機器人競賽教程:機械、巡線與PID
- TypeScript項目開發實戰
- Java項目實戰精編
- concrete5 Cookbook
- 青少年信息學競賽
- App Inventor創意趣味編程進階
- 零基礎學C語言(升級版)
- Exploring SE for Android