OneSignal / OneSignal-Cordova-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Ionic, PhoneGap CLI, PhoneGap Build, Cordova, or Sencha Touch app with OneSignal. Supports Android, iOS, and Amazon's Fire OS platforms. https://onesignal.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: Plugin interferes with Web SDK Service Worker causes SW to throw exceptions

NikitaKA opened this issue · comments

What happened?

When building PWA (browser platform) plugin starts to interfere with Service Worker from Web SDK. This causes Service Worker to throw exceptions (many different types). The only way I found how to fix that is to manually edit the /platforms/browser/platform_www/cordova_plugins.js file and remove everything linked to cordova-onesignal-plugin.

Steps to reproduce?

Install both onesignal-cordova-plugin and Web SDK Service Worker. First for iOS and Android, second for PWA. Setup Web SDK, install PWA to the phone. Open it, subscribe (see Quick Start guide), nothing special. Then close PWA and open it again: you will get exceptions. Refreshing a page sometimes helps. Sometimes you need to stop SW and clear site data. But every time when your PWA is closed and you receive push - PWA will open with exceptions. Tested on Android 14 in Chrome.

Remove onesignal-cordova-plugin (or modify cordova_plugins.js file in browser platform) and PWA will immediately start to work like a charm.

What did you expect to happen?

Plugin not installed for the browser platform, /platforms/browser/platform_www/cordova_plugins.js does not contain any mention of this plugin.

Dev from Cordova asked to my issue about that: apache/cordova-lib#892 (comment)

In onesignal's case, they are providing a JS module for all platforms (because it's not isolated inside a block. If onesignal uses an alternate library for the browser that isn't a cordova plugin, then they should be able to move

<js-module src="dist/index.js" name="OneSignalPlugin">
<clobbers target="OneSignal" />
</js-module>
into the block, but they'll need to have 2 copies of it, one for iOS and one for android. This should prevent the JS module from being installed for browser targets, but have it installed for iOS and android targets. Again suggesting this more as a workaround, but if one signal's plugin doesn't support browser, it might be better for one signal to adjust their config so it won't be installed on browser targets to begin with.

OneSignal Cordova SDK version

5

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

Uncaught (in promise) n: OneSignal.context is undefined. Make sure to call OneSignal.init() before calling getPermissionStatus().
    at pe.<anonymous> (https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.es6.js?v=160101:1:42784)
    at Generator.next (<anonymous>)
    at https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.es6.js?v=160101:1:260596
    at new Promise (<anonymous>)
    at o (https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.es6.js?v=160101:1:260341)
    at pe.getPermissionStatus (https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.es6.js?v=160101:1:42723)
    at nn.<anonymous> (https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.es6.js?v=160101:1:219668)
    at Generator.next (<anonymous>)
    at r (https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.es6.js?v=160101:1:260398)


Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'userConfig')
    at bi.<anonymous> (InitHelper.js:291:47)
    at Generator.next (<anonymous>)
    at tslib.es6.js:121:71
    at new Promise (<anonymous>)
    at o (tslib.es6.js:117:12)
    at bi.handleAutoResubscribe (OneSignalSDK.page.es6.js?v=160101:1:170304)
    at bi.<anonymous> (InitHelper.js:63:26)
    at Generator.next (<anonymous>)
    at r (tslib.es6.js:118:58)

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'serviceWorkerManager')
    at bi.<anonymous> (InitHelper.js:20:33)
    at Generator.next (<anonymous>)
    at tslib.es6.js:121:71
    at new Promise (<anonymous>)
    at o (tslib.es6.js:117:12)
    at bi.internalInit (OneSignalSDK.page.es6.js?v=160101:1:163203)
    at OneSignal.js:141:30
    at Generator.next (<anonymous>)
    at r (tslib.es6.js:118:58)

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'subscriptionManager')
    at bi.<anonymous> (InitHelper.js:58:52)
    at Generator.next (<anonymous>)
    at r (tslib.es6.js:118:58)

Code of Conduct

  • I agree to follow this project's Code of Conduct