From 1f361bc09103730d1a8d77c099d1f06ecf5eee6b Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 27 Sep 2018 10:51:32 -0400 Subject: [PATCH] bitwarden frame id for safari autofills --- src/browser/browserApi.ts | 7 ++++++- src/content/autofill.js | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/browser/browserApi.ts b/src/browser/browserApi.ts index 81512fb561..316107599c 100644 --- a/src/browser/browserApi.ts +++ b/src/browser/browserApi.ts @@ -120,6 +120,10 @@ export class BrowserApi { delete obj.tab.safariTab; } + if (options != null && options.frameId != null && obj.bitwardenFrameId == null) { + obj.bitwardenFrameId = options.frameId; + } + if (t.page) { t.page.dispatchMessage('bitwarden', obj); } @@ -199,7 +203,8 @@ export class BrowserApi { safari.application.addEventListener('message', async (msgEvent: any) => { callback(msgEvent.message, { tab: BrowserApi.makeTabObject(msgEvent.target), - frameId: null, + frameId: msgEvent.message != null && msgEvent.message.bitwardenFrameId != null ? + msgEvent.message.bitwardenFrameId : null, }, () => { /* No responses in Safari */ }); }, false); } diff --git a/src/content/autofill.js b/src/content/autofill.js index 55cd9c8676..4041dfcc7f 100644 --- a/src/content/autofill.js +++ b/src/content/autofill.js @@ -986,8 +986,15 @@ if ((typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 && navigator.userAgent.indexOf('Chrome') === -1) { + if (window.__bitwardenFrameId == null) { + window.__bitwardenFrameId = Math.floor(Math.random() * Math.floor(99999999)); + } safari.self.addEventListener('message', function (msgEvent) { var msg = msgEvent.message; + if(msg.bitwardenFrameId != null && window.__bitwardenFrameId !== msg.bitwardenFrameId) { + return; + } + if (msg.command === 'collectPageDetails') { var pageDetails = collect(document); var pageDetailsObj = JSON.parse(pageDetails); @@ -995,7 +1002,8 @@ command: 'collectPageDetailsResponse', tab: msg.tab, details: pageDetailsObj, - sender: msg.sender + sender: msg.sender, + bitwardenFrameId: window.__bitwardenFrameId }); } else if (msg.command === 'fillForm') {