Skip to content

Cordova is not defined RefrenceError Chrome #278

@ChariseWalraven

Description

@ChariseWalraven

Hi there,

I noticed in the documentation for the Device JS API page there's an if statement checking for the existence of cordova before using some cordova specific code that isn't available on web.

The code doesn't work in Chrome (and as such won't work in web apps or the device preview), and instead results in a ReferenceError, like this:

Uncaught ReferenceError: cordova is not defined

This can be resolved by replacing cordova with window.cordova, so the code will become this:

// get device information
if (window.cordova) {
  $public.Device.whenReady().then(function() {
    $parameters.DeviceModel = device.model;
    $parameters.CordovaVersion = device.cordova;
    $parameters.Platform = device.platform;
    $parameters.UUID = device.uuid;
    $parameters.Version = device.version;
    $parameters.Manufacturer = device.manufacturer;
    $parameters.IsSimulator = device.isVirtual;
    $parameters.SerialNumber = device.serial;
    $resolve();
  });
} else {
  // fallback when testing on desktop browser
  $resolve();
}

To avoid confusing people who don't know JavaScript, it might be worth replacing the references to cordova with window.cordova in the Reactive and Mobile documentation.

Edit: added link to documentation where I noticed the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions