Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cordova is not defined RefrenceError Chrome #278

Open
ChariseWalraven opened this issue Sep 6, 2022 · 0 comments
Open

Cordova is not defined RefrenceError Chrome #278

ChariseWalraven opened this issue Sep 6, 2022 · 0 comments

Comments

@ChariseWalraven
Copy link

ChariseWalraven commented Sep 6, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant