bitwarden frame id for safari autofills

This commit is contained in:
Kyle Spearrin 2018-09-27 10:51:32 -04:00
parent 82d14750e7
commit 1f361bc091
2 changed files with 15 additions and 2 deletions

View File

@ -120,6 +120,10 @@ export class BrowserApi {
delete obj.tab.safariTab; delete obj.tab.safariTab;
} }
if (options != null && options.frameId != null && obj.bitwardenFrameId == null) {
obj.bitwardenFrameId = options.frameId;
}
if (t.page) { if (t.page) {
t.page.dispatchMessage('bitwarden', obj); t.page.dispatchMessage('bitwarden', obj);
} }
@ -199,7 +203,8 @@ export class BrowserApi {
safari.application.addEventListener('message', async (msgEvent: any) => { safari.application.addEventListener('message', async (msgEvent: any) => {
callback(msgEvent.message, { callback(msgEvent.message, {
tab: BrowserApi.makeTabObject(msgEvent.target), tab: BrowserApi.makeTabObject(msgEvent.target),
frameId: null, frameId: msgEvent.message != null && msgEvent.message.bitwardenFrameId != null ?
msgEvent.message.bitwardenFrameId : null,
}, () => { /* No responses in Safari */ }); }, () => { /* No responses in Safari */ });
}, false); }, false);
} }

View File

@ -986,8 +986,15 @@
if ((typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 && if ((typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 &&
navigator.userAgent.indexOf('Chrome') === -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) { safari.self.addEventListener('message', function (msgEvent) {
var msg = msgEvent.message; var msg = msgEvent.message;
if(msg.bitwardenFrameId != null && window.__bitwardenFrameId !== msg.bitwardenFrameId) {
return;
}
if (msg.command === 'collectPageDetails') { if (msg.command === 'collectPageDetails') {
var pageDetails = collect(document); var pageDetails = collect(document);
var pageDetailsObj = JSON.parse(pageDetails); var pageDetailsObj = JSON.parse(pageDetails);
@ -995,7 +1002,8 @@
command: 'collectPageDetailsResponse', command: 'collectPageDetailsResponse',
tab: msg.tab, tab: msg.tab,
details: pageDetailsObj, details: pageDetailsObj,
sender: msg.sender sender: msg.sender,
bitwardenFrameId: window.__bitwardenFrameId
}); });
} }
else if (msg.command === 'fillForm') { else if (msg.command === 'fillForm') {