Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14.21.1
FROM node:22
WORKDIR /sdk
COPY package.json .
RUN yarn
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"bowser": "github:OneSignal/bowser#fix-android8-opr6-build-detection",
"jsdom": "^9.12.0",
"jsonp": "github:OneSignal/jsonp#onesignal",
"node-sass": "^4.9.0",
"npm-css": "https://registry.npmjs.org/npm-css/-/npm-css-0.2.3.tgz",
"postcss-discard-comments": "https://registry.npmjs.org/postcss-discard-comments/-/postcss-discard-comments-2.0.4.tgz",
"postcss-filter-plugins": "https://registry.npmjs.org/postcss-filter-plugins/-/postcss-filter-plugins-2.0.2.tgz",
"sass": "^1.90.0",
"tslib": "^1.9.0",
"validator": "https://registry.npmjs.org/validator/-/validator-6.0.0.tgz"
},
Expand Down Expand Up @@ -40,7 +40,7 @@
"jest": "jest --coverage"
},
"config": {
"sdkVersion": "151606"
"sdkVersion": "1516010"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -88,7 +88,7 @@
"nyc": "^11.1.0",
"postcss-loader": "^2.0.6",
"prettier": "^2.7.1",
"sass-loader": "^6.0.6",
"sass-loader": "8.0.2",
"sinon": "^2.4.1",
"svgo": "^0.7.2",
"text-encoding": "^0.6.4",
Expand All @@ -98,7 +98,7 @@
"uglifyjs-webpack-plugin": "^1.2.4",
"webpack": "^4.3.0",
"webpack-bundle-analyzer": "^3.3.2",
"webpack-cli": "^2.0.13"
"webpack-cli": "3.3.12"
},
"ava": {
"extensions": [
Expand Down Expand Up @@ -150,5 +150,6 @@
"maxSize": "9 kB",
"compression": "gzip"
}
]
],
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
4 changes: 2 additions & 2 deletions src/libraries/WorkerMessenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class WorkerMessenger {
Log.debug(`(${location.origin}) [Worker Messenger] Page is now listening for messages.`);
}

onWorkerMessageReceivedFromPage(event: ServiceWorkerMessageEvent) {
onWorkerMessageReceivedFromPage(event: any) {
const data: WorkerMessengerMessage = event.data;

/* If this message doesn't contain our expected fields, discard the message */
Expand Down Expand Up @@ -235,7 +235,7 @@ export class WorkerMessenger {
message topic. If no one is listening to the message, it is discarded;
otherwise, the listener callback is executed.
*/
onPageMessageReceivedFromServiceWorker(event: ServiceWorkerMessageEvent) {
onPageMessageReceivedFromServiceWorker(event: any) {
const data: WorkerMessengerMessage = event.data;

/* If this message doesn't contain our expected fields, discard the message */
Expand Down
14 changes: 0 additions & 14 deletions src/libraries/sw/Log.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
import { OSServiceWorkerFields } from "../../service-worker/types";

declare var self: ServiceWorkerGlobalScope & OSServiceWorkerFields;

export default class Log {
static debug(...args: any[]): void {
if (!!self.shouldLog) {
console.debug(...args);
}
}
static trace(...args: any[]): void {
if (!!self.shouldLog) {
console.trace(...args);
}
}
static info(...args: any[]): void {
if (!!self.shouldLog) {
console.info(...args);
}
}
static warn(...args: any[]): void {
if (!!self.shouldLog) {
console.warn(...args);
}
}
static error(...args: any[]): void {
if (!!self.shouldLog) {
console.error(...args);
}
}
}
1 change: 1 addition & 0 deletions src/modules/frames/ProxyFrame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default class ProxyFrame extends RemoteFrame {

// 3/30/16: For HTTP sites, put the host page URL as default URL if one doesn't exist already
const defaultUrl = await Database.get('Options', 'defaultUrl');
Log.info("Default URL from database:", defaultUrl, new URL(OneSignal.config.pageUrl).origin);
if (!defaultUrl) {
await Database.put('Options', { key: 'defaultUrl', value: new URL(OneSignal.config.pageUrl).origin });
}
Expand Down
42 changes: 30 additions & 12 deletions src/service-worker/ServiceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export class ServiceWorker {
const appId = await ServiceWorker.getAppId();

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

const notificationReceived: NotificationReceived = {
Expand All @@ -266,10 +266,16 @@ export class ServiceWorker {
notificationEventPromiseFns.push((notif => {
return ServiceWorker.displayNotification(notif)
.then(() => {
console.log(`Notification displayed then 1`);
return ServiceWorker.workerMessenger.broadcast(WorkerMessengerCommand.NotificationDisplayed, notif).catch(e => Log.error(e));
})
.then(() => ServiceWorker.executeWebhooks('notification.displayed', notif)
.then(() => ServiceWorker.sendConfirmedDelivery(notif)).catch(e => Log.error(e)));
.then(() => {
console.log(`Notification displayed then 2`);
ServiceWorker.executeWebhooks('notification.displayed', notif)})
.then(() => {
console.log(`Notification displayed then 3`);
ServiceWorker.sendConfirmedDelivery(notif)
}).catch(e => Log.error(e));
}).bind(null, notification));
}

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

notification.heading = notification.heading ? notification.heading : defaultTitle;
notification.icon = notification.icon ? notification.icon : (defaultIcon ? defaultIcon : undefined);
Expand All @@ -644,8 +651,10 @@ export class ServiceWorker {
overrides = {};
notification = { ...notification, ...overrides };

Log.debug("before ensureNotificationResourcesHttps", );
ServiceWorker.ensureNotificationResourcesHttps(notification);

Log.debug("after ensureNotificationResourcesHttps", );
const notificationOptions = {
body: notification.content,
icon: notification.icon,
Expand Down Expand Up @@ -679,7 +688,7 @@ export class ServiceWorker {
seconds unless requireInteraction is set to true. See:
https://developers.google.com/web/updates/2015/10/notification-requireInteractiom
*/
requireInteraction: extra.persistNotification,
// requireInteraction: extra.persistNotification,
/*
On Chrome 50+, by default notifications replacing
identically-tagged notifications no longer vibrate/signal the user
Expand Down Expand Up @@ -708,9 +717,12 @@ export class ServiceWorker {
long to pause. For example [300, 100, 400] would vibrate 300ms,
pause 100ms, then vibrate 400ms.
*/
vibrate: notification.vibrate
vibrate: notification.vibrate,
requireInteraction: true, // Forces notification to stay visible
silent: false
};

Log.debug("before showNotification", self.registration, notification.heading, notificationOptions);
return self.registration.showNotification(notification.heading, notificationOptions);
}

Expand All @@ -720,9 +732,12 @@ export class ServiceWorker {
* @param url
*/
static shouldOpenNotificationUrl(url) {
return (url !== 'javascript:void(0);' &&
url !== 'do_not_open' &&
!Utils.contains(url, '_osp=do_not_open'));
const shouldOpen =(url !== 'javascript:void(0);' &&
url !== 'do_not_open' &&
!Utils.contains(url, '_osp=do_not_open'));

Log.debug(`Called %cshouldOpenNotificationUrl(${url}):`, url, shouldOpen);
return shouldOpen;
}

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

Log.debug("SW URL", launchUrl, dbDefaultNotificationUrl, notification?.url)
// If the user clicked an action button, use the URL provided by the action button
// Unless the action button URL is null
if (notification.action) {
if (notification && notification.action) {
// Find the URL tied to the action button that was clicked
for (const button of notification.buttons) {
if (button.action === notification.action &&
Expand All @@ -764,7 +781,7 @@ export class ServiceWorker {
launchUrl = button.url;
}
}
} else if (notification.url &&
} else if (notification && notification.url &&
notification.url !== '') {
// The user clicked the notification body instead of an action button
launchUrl = notification.url;
Expand All @@ -778,7 +795,7 @@ export class ServiceWorker {
* dismissed by clicking the 'X' icon. See the notification close event for the dismissal event.
*/
static async onNotificationClicked(event: NotificationEventInit) {
Log.debug(`Called %conNotificationClicked(${JSON.stringify(event, null, 4)}):`, Utils.getConsoleStyle('code'), event);
Log.debug("Called onNotificationClicked", JSON.stringify(event));

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

Log.info("NotificationClicked appId", appId);
let saveNotificationClickedPromise: Promise<void> | undefined;
const notificationClicked: NotificationClicked = {
notificationId: notificationData.id,
notificationId: notificationData?.id,
appId,
url: launchUrl,
timestamp: new Date().getTime(),
Expand Down
14 changes: 14 additions & 0 deletions typings/globals/serviceworker.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
declare module 'ServiceWorker' {
// eslint-disable-next-line no-var, @typescript-eslint/no-explicit-any
var OneSignal: any;
export = OneSignal;
}

interface PushSubscriptionChangeEvent extends ExtendableEvent {
readonly oldSubscription: PushSubscription | null;
readonly newSubscription: PushSubscription | null;
}

/* eslint-disable no-var */
declare var PushSubscriptionChangeEvent: {
prototype: PushSubscriptionChangeEvent;
new(): PushSubscriptionChangeEvent;
};
/* eslint-enable no-var */

Loading
Loading