mapiacompany / capacitor-codepush

Capacitor plugin for CodePush
http://appcenter.ms
Other
151 stars 65 forks source link

CodePush causes uncaught exceptions when previewing project on a web browser #40

Open Clovel opened 3 years ago

Clovel commented 3 years ago

Description

When debugging or developing an app using a web browser (for example for styling development), CodePush throws an uncaught exception that does not come from the app's source code.

Additional Information

This issue does not happen with other Capacitor plugins that are "mobile-only". A good example is the Firebase notification plugin.

Screenshots

Exception :

Capture_d_écran_2021-06-30_à_15 39 29

Code extract : Capture_d_écran_2021-06-30_à_15 40 08

ashish141199 commented 3 years ago

You are not supposed to use it on web. Use an if statement:

something like this

if(platform == 'web') return;
// rest of the code
Clovel commented 3 years ago

I know that. But simply importing the plugin, registering it, causes the exception. On the contrary, other Capacitor or Cordova plugins catch these exceptions.

We should mimic that behavior for this plugin.

Clovel commented 2 years ago

Perhaps doing something like this would be acceptable ?

let codePushInstance: CodePush | null = null;
if(Capacitor.getPlatform() !== 'web') {
  codePushInstance = new CodePush();
  (window as any).codePush = codePushInstance;
} else {
  /* Can't use CodePush without Capacitor */
  /* The instance will be null */
}

export const codePush: CodePush | null = codePushInstance;

The downside is that the nullish case should be managed by the developer usign this package.