-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example of a root service worker
This is to test OneSignal with conflicting a root service worker. This causes the OneSignal SDK to sometimes not include a push token when it makes a REST API to POST /users. This is due to the OneSignal SDK sometimes getting the registration for the root service worker due to a race condition, instead of the OneSignal service worker. We will fix this problem in a follow up commit.
- Loading branch information
Showing
3 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Example of a root scope service worker a site might have. | ||
// This tests to ensure OneSignal can use the correctly scoped one when | ||
// 2 service workers are in play. | ||
|
||
// This exists to point out the fact this service worker is being | ||
// used instead of the intended OneSignalSDKWorker.js. | ||
self.addEventListener('push', async (e) => { | ||
console.error("push - Should not fire on sw.js"); | ||
|
||
const options = { | ||
body: 'Non-SDK from sw.js', | ||
}; | ||
|
||
// Display notification | ||
const displayPromise = self.registration.showNotification('Non-SDK from sw.js', options); | ||
|
||
// Must wait for all promises to finish before return from this event. | ||
e.waitUntil(displayPromise); | ||
}); |