From 8c36ddf91c216e7f66398f2b4f646e634babe6de Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 12 Aug 2019 15:50:47 -0400 Subject: [PATCH] safariapp method updates --- src/browser/safariApp.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/browser/safariApp.ts b/src/browser/safariApp.ts index 6c78cddaa9..43fe17e3e1 100644 --- a/src/browser/safariApp.ts +++ b/src/browser/safariApp.ts @@ -4,7 +4,7 @@ export class SafariApp { static init() { if (BrowserApi.isSafariApi) { (window as any).bitwardenSafariAppMessageReceiver = (message: any) => - SafariApp.receiveMessageFromApp(message); + SafariApp.receiveMessageFromApp(message == null ? null : JSON.parse(message)); } } @@ -13,17 +13,18 @@ export class SafariApp { return Promise.resolve(null); } return new Promise((resolve) => { - const messageId = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); - (window as any).webkit.messageHandlers.bitwardenApp.postMessage({ + const now = new Date(); + const messageId = now.getTime().toString() + '_' + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); + (window as any).webkit.messageHandlers.bitwardenApp.postMessage(JSON.stringify({ id: messageId, command: command, data: data, - }); - SafariApp.requests.set(messageId, { resolve: resolve, date: new Date() }); + })); + SafariApp.requests.set(messageId, { resolve: resolve, date: now }); }); } - private static requests = new Map void, date: Date }>(); + private static requests = new Map void, date: Date }>(); private static receiveMessageFromApp(message: any) { if (message == null || message.id == null || !SafariApp.requests.has(message.id)) {