Fauxgap Javascript

What It Is

The sample html5 workspace provided with the Intel® HTML5 Development Environment contains a small file named fauxgap.js. This script fulfills the entire Apache Cordova* (PhoneGap) API and is configurable. It can be used with pages that are being tested with Preview or for unit testing.

Relationship with the Device Emulator

The Intel HTML5 Development Environment includes a Device Emulator (see the Getting Started Guide: Intel HTML5 Development Environment/Device Emulator). The Device Emulator provides a superior way of executing apps that use the Cordova API and it does not need fauxgap.js at all. The API input is directly and easily controllable in the Device Emulator UI, and the app is correctly sized to the various mobile devices. Additionally certain Cordova events can be fired.

Fauxgap.js is not intended for use with the Device Emulator; it is used when you run your application under the Preview in Browser operation.

Setting Up

Getting started with fauxgap.js is easy. Simply:

  • Copy the fauxgap.js file from the default project folder to your own projects folder
  • Modify your <script> tag to refer to fauxgap.js instead of cordova.js: <script src="fauxgap.js"></script>

Warning - Do NOT package fauxgap.js

The fauxgap.js will interfere with the Device Emulator.  It will also wreak havoc if used by your app when it is built by PhoneGap Build*.  Be sure to restore the <script> tag back to cordova.js before packaging your app or before running in the Device Emulator.

Random Data

Some API callbacks that are expecting data from the device (like the accelerometer) may receive random data. This behavior is usually configurable. The point is that fauxgap.js doesn't try to pretend the device is being handled by a real person, it simply provides changing data so callback routines can be tested.

Configuring fauxgap.js

Near the top of fauxgap.js there is a large fauxgap_ini  block. It is a JavaScript object with dozens of attributes. It should be fairly clear what each attribute controls. Change their values to change the behavior of the fauxgap.js provided Cordova API.  In particular, if you wish to test your error handling routines, that is easily configured.  Here is a sample of the fauxgap_ini block:

var fauxgap_ini =  { 
                    faux_device: "when-missing",
                    device_properties: {name:"faux device", cordova:"2.1.0",
                       phonegap:"2.1.0", platform:"iPhone",
                       uuid:"fauxgap-simulated-uuid", version:"6.0"}, 

                    // values: "never", "when-missing", "always"
                                 faux_accelerometer: "when-missing",
                    //change to false to have error handler called.
                    getCurrentAcceleration_succeeds: true,
                    accelerometer_at_rest: false,
                    faux_camera: "when-missing",
                    getPicture_succeeds: true,


Each of the domains of the Cordova API has a faux named attribute.  Example: faux_accelerometer .  The three possible values are "when-missing", "never" or "always".  "when-missing" means that fauxgap.js should only provide this API if it does not already exist in the DOM.  Use of "always" means that fauxgap.js should always provide that API, even overriding an existing one in the DOM.  And "never" tells fauxgap.js to not implement that particular API.


Certain API functions, or groups of functions, accept a success callback as well as an error callback.  If the matching succeeds attribute is true then the success callback for that function will be called, otherwise the failure callback will be called.

Einzelheiten zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.