1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 17:53:39 +00:00

Revert "Safari Web Extension Port from App Extension"

This commit is contained in:
Chad Scharf
2021-01-13 17:08:33 -05:00
committed by GitHub
parent ebd2439edd
commit 336f8f3117
47 changed files with 1950 additions and 664 deletions

View File

@@ -3,17 +3,44 @@ document.addEventListener('DOMContentLoaded', (event) => {
let filledThisHref = false;
let delayFillTimeout: number;
const enabledKey = 'enableAutoFillOnPageLoad';
chrome.storage.local.get(enabledKey, (obj: any) => {
if (obj != null && obj[enabledKey] === true) {
setInterval(() => doFillIfNeeded(), 500);
const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 &&
navigator.userAgent.indexOf('Chrome') === -1;
if (isSafari) {
if ((window as any).__bitwardenFrameId == null) {
(window as any).__bitwardenFrameId = Math.floor(Math.random() * Math.floor(99999999));
}
});
chrome.runtime.onMessage.addListener((msg: any, sender: any, sendResponse: Function) => {
if (msg.command === 'fillForm' && pageHref === msg.url) {
filledThisHref = true;
}
});
const responseCommand = 'autofillerAutofillOnPageLoadEnabledResponse';
safari.extension.dispatchMessage('bitwarden', {
command: 'bgGetDataForTab',
responseCommand: responseCommand,
bitwardenFrameId: (window as any).__bitwardenFrameId,
});
safari.self.addEventListener('message', (msgEvent: any) => {
const msg = JSON.parse(msgEvent.message.msg);
if (msg.bitwardenFrameId != null && (window as any).__bitwardenFrameId !== msg.bitwardenFrameId) {
return;
}
if (msg.command === responseCommand && msg.data.autofillEnabled === true) {
setInterval(() => doFillIfNeeded(), 500);
} else if (msg.command === 'fillForm' && pageHref === msg.url) {
filledThisHref = true;
}
}, false);
return;
} else {
const enabledKey = 'enableAutoFillOnPageLoad';
chrome.storage.local.get(enabledKey, (obj: any) => {
if (obj != null && obj[enabledKey] === true) {
setInterval(() => doFillIfNeeded(), 500);
}
});
chrome.runtime.onMessage.addListener((msg: any, sender: any, sendResponse: Function) => {
if (msg.command === 'fillForm' && pageHref === msg.url) {
filledThisHref = true;
}
});
}
function doFillIfNeeded(force: boolean = false) {
if (force || pageHref !== window.location.href) {
@@ -37,7 +64,12 @@ document.addEventListener('DOMContentLoaded', (event) => {
sender: 'autofiller',
};
chrome.runtime.sendMessage(msg);
if (isSafari) {
msg.bitwardenFrameId = (window as any).__bitwardenFrameId;
safari.extension.dispatchMessage('bitwarden', msg);
} else {
chrome.runtime.sendMessage(msg);
}
}
}
});