Skip to content

Commit 02fee96

Browse files
committed
[tbd] logging
1 parent b8d0d84 commit 02fee96

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"jest": "jest --coverage"
4141
},
4242
"config": {
43-
"sdkVersion": "151606"
43+
"sdkVersion": "1516010"
4444
},
4545
"repository": {
4646
"type": "git",

src/libraries/sw/Log.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,17 @@
1-
import { OSServiceWorkerFields } from "../../service-worker/types";
2-
3-
declare var self: ServiceWorkerGlobalScope & OSServiceWorkerFields;
4-
51
export default class Log {
62
static debug(...args: any[]): void {
7-
if (!!self.shouldLog) {
83
console.debug(...args);
9-
}
104
}
115
static trace(...args: any[]): void {
12-
if (!!self.shouldLog) {
136
console.trace(...args);
14-
}
157
}
168
static info(...args: any[]): void {
17-
if (!!self.shouldLog) {
189
console.info(...args);
19-
}
2010
}
2111
static warn(...args: any[]): void {
22-
if (!!self.shouldLog) {
2312
console.warn(...args);
24-
}
2513
}
2614
static error(...args: any[]): void {
27-
if (!!self.shouldLog) {
2815
console.error(...args);
29-
}
3016
}
3117
}

src/modules/frames/ProxyFrame.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export default class ProxyFrame extends RemoteFrame {
100100

101101
// 3/30/16: For HTTP sites, put the host page URL as default URL if one doesn't exist already
102102
const defaultUrl = await Database.get('Options', 'defaultUrl');
103+
Log.info("Default URL from database:", defaultUrl, new URL(OneSignal.config.pageUrl).origin);
103104
if (!defaultUrl) {
104105
await Database.put('Options', { key: 'defaultUrl', value: new URL(OneSignal.config.pageUrl).origin });
105106
}

src/service-worker/ServiceWorker.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export class ServiceWorker {
249249
const appId = await ServiceWorker.getAppId();
250250

251251
for (const rawNotification of notifications) {
252-
Log.debug('Raw Notification from OneSignal:', rawNotification);
252+
Log.debug('Raw Notification from OneSignal:', JSON.stringify(rawNotification));
253253
const notification = ServiceWorker.buildStructuredNotificationObject(rawNotification);
254254

255255
const notificationReceived: NotificationReceived = {
@@ -266,10 +266,16 @@ export class ServiceWorker {
266266
notificationEventPromiseFns.push((notif => {
267267
return ServiceWorker.displayNotification(notif)
268268
.then(() => {
269+
console.log(`Notification displayed then 1`);
269270
return ServiceWorker.workerMessenger.broadcast(WorkerMessengerCommand.NotificationDisplayed, notif).catch(e => Log.error(e));
270271
})
271-
.then(() => ServiceWorker.executeWebhooks('notification.displayed', notif)
272-
.then(() => ServiceWorker.sendConfirmedDelivery(notif)).catch(e => Log.error(e)));
272+
.then(() => {
273+
console.log(`Notification displayed then 2`);
274+
ServiceWorker.executeWebhooks('notification.displayed', notif)})
275+
.then(() => {
276+
console.log(`Notification displayed then 3`);
277+
ServiceWorker.sendConfirmedDelivery(notif)
278+
}).catch(e => Log.error(e));
273279
}).bind(null, notification));
274280
}
275281

@@ -631,6 +637,7 @@ export class ServiceWorker {
631637
const persistNotification = await Database.get('Options', 'persistNotification');
632638
// Get app ID for tag value
633639
const appId = await ServiceWorker.getAppId();
640+
Log.debug("appId", appId);
634641

635642
notification.heading = notification.heading ? notification.heading : defaultTitle;
636643
notification.icon = notification.icon ? notification.icon : (defaultIcon ? defaultIcon : undefined);
@@ -644,8 +651,10 @@ export class ServiceWorker {
644651
overrides = {};
645652
notification = { ...notification, ...overrides };
646653

654+
Log.debug("before ensureNotificationResourcesHttps", );
647655
ServiceWorker.ensureNotificationResourcesHttps(notification);
648656

657+
Log.debug("after ensureNotificationResourcesHttps", );
649658
const notificationOptions = {
650659
body: notification.content,
651660
icon: notification.icon,
@@ -679,7 +688,7 @@ export class ServiceWorker {
679688
seconds unless requireInteraction is set to true. See:
680689
https://developers.google.com/web/updates/2015/10/notification-requireInteractiom
681690
*/
682-
requireInteraction: extra.persistNotification,
691+
// requireInteraction: extra.persistNotification,
683692
/*
684693
On Chrome 50+, by default notifications replacing
685694
identically-tagged notifications no longer vibrate/signal the user
@@ -708,9 +717,12 @@ export class ServiceWorker {
708717
long to pause. For example [300, 100, 400] would vibrate 300ms,
709718
pause 100ms, then vibrate 400ms.
710719
*/
711-
vibrate: notification.vibrate
720+
vibrate: notification.vibrate,
721+
requireInteraction: true, // Forces notification to stay visible
722+
silent: false
712723
};
713724

725+
Log.debug("before showNotification", self.registration, notification.heading, notificationOptions);
714726
return self.registration.showNotification(notification.heading, notificationOptions);
715727
}
716728

@@ -720,9 +732,12 @@ export class ServiceWorker {
720732
* @param url
721733
*/
722734
static shouldOpenNotificationUrl(url) {
723-
return (url !== 'javascript:void(0);' &&
724-
url !== 'do_not_open' &&
725-
!Utils.contains(url, '_osp=do_not_open'));
735+
const shouldOpen =(url !== 'javascript:void(0);' &&
736+
url !== 'do_not_open' &&
737+
!Utils.contains(url, '_osp=do_not_open'));
738+
739+
Log.debug(`Called %cshouldOpenNotificationUrl(${url}):`, url, shouldOpen);
740+
return shouldOpen;
726741
}
727742

728743
/**
@@ -744,6 +759,7 @@ export class ServiceWorker {
744759
* notification body was clicked.
745760
*/
746761
static async getNotificationUrlToOpen(notification): Promise<string> {
762+
Log.debug("getNotificationUrlToOpen", JSON.stringify(notification));
747763
// Defaults to the URL the service worker was registered
748764
// TODO: This should be fixed for HTTP sites
749765
let launchUrl = location.origin;
@@ -753,9 +769,10 @@ export class ServiceWorker {
753769
if (dbDefaultNotificationUrl)
754770
launchUrl = dbDefaultNotificationUrl;
755771

772+
Log.debug("SW URL", launchUrl, dbDefaultNotificationUrl, notification?.url)
756773
// If the user clicked an action button, use the URL provided by the action button
757774
// Unless the action button URL is null
758-
if (notification.action) {
775+
if (notification && notification.action) {
759776
// Find the URL tied to the action button that was clicked
760777
for (const button of notification.buttons) {
761778
if (button.action === notification.action &&
@@ -764,7 +781,7 @@ export class ServiceWorker {
764781
launchUrl = button.url;
765782
}
766783
}
767-
} else if (notification.url &&
784+
} else if (notification && notification.url &&
768785
notification.url !== '') {
769786
// The user clicked the notification body instead of an action button
770787
launchUrl = notification.url;
@@ -778,7 +795,7 @@ export class ServiceWorker {
778795
* dismissed by clicking the 'X' icon. See the notification close event for the dismissal event.
779796
*/
780797
static async onNotificationClicked(event: NotificationEventInit) {
781-
Log.debug(`Called %conNotificationClicked(${JSON.stringify(event, null, 4)}):`, Utils.getConsoleStyle('code'), event);
798+
Log.debug("Called onNotificationClicked", JSON.stringify(event));
782799

783800
// Close the notification first here, before we do anything that might fail
784801
event.notification.close();
@@ -805,9 +822,10 @@ export class ServiceWorker {
805822
const appId = await ServiceWorker.getAppId();
806823
const deviceType = DeviceRecord.prototype.getDeliveryPlatform();
807824

825+
Log.info("NotificationClicked appId", appId);
808826
let saveNotificationClickedPromise: Promise<void> | undefined;
809827
const notificationClicked: NotificationClicked = {
810-
notificationId: notificationData.id,
828+
notificationId: notificationData?.id,
811829
appId,
812830
url: launchUrl,
813831
timestamp: new Date().getTime(),

0 commit comments

Comments
 (0)