mirror of
https://github.com/bitwarden/browser.git
synced 2024-06-29 11:05:54 +02:00
f0cdcccf81
* changed content script injection strategy * added persistent connection and reinjection of the content script * cleanup resources on disconnect * cleanup resources on disconnect * concluded messanger event listeners cleanup and added unit tests * Switched to use browser api add listener instead of navtive apis * renamed cleanup to destroy and added reconnect and disconnect command functions * refactored to use foreach and check for only https urls * refactored the content script to only load the page script if it currently doesn't extist of the page, and if it does sends a reconnect command to the page-script to replace the native webauthn methods * updated unit test * removed memoized logic * moved the send disconect command to the messenger * updated unit test * test messenger handler * [PM-4012] fix: add `senderId` to messenger * destroy pending requets * cleaned up page script and terminated pending request * fixed cannot read properties of undefined * rearranged functions, renamed misspelled words, and created test * mocked EventTarget as there are issues on jest for listeners getting the events * Return fall back error instead * Update apps/browser/src/vault/fido2/content/content-script.ts Co-authored-by: Cesar Gonzalez <cesar.a.gonzalezcs@gmail.com> * Update apps/browser/src/vault/fido2/content/messaging/messenger.ts Co-authored-by: Cesar Gonzalez <cesar.a.gonzalezcs@gmail.com> * removed whitespace --------- Co-authored-by: Andreas Coroiu <andreas.coroiu@gmail.com> Co-authored-by: Cesar Gonzalez <cesar.a.gonzalezcs@gmail.com>
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { BrowserApi } from "../../platform/browser/browser-api";
|
|
|
|
import { Fido2Service as Fido2ServiceInterface } from "./abstractions/fido2.service";
|
|
|
|
export default class Fido2Service implements Fido2ServiceInterface {
|
|
async init() {
|
|
const tabs = await BrowserApi.tabsQuery({});
|
|
tabs.forEach((tab) => {
|
|
if (tab.url?.startsWith("https")) {
|
|
this.injectFido2ContentScripts({ tab } as chrome.runtime.MessageSender);
|
|
}
|
|
});
|
|
|
|
BrowserApi.addListener(chrome.runtime.onConnect, (port) => {
|
|
if (port.name === "fido2ContentScriptReady") {
|
|
port.postMessage({ command: "fido2ContentScriptInit" });
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Injects the FIDO2 content script into the current tab.
|
|
* @param {chrome.runtime.MessageSender} sender
|
|
* @returns {Promise<void>}
|
|
*/
|
|
async injectFido2ContentScripts(sender: chrome.runtime.MessageSender): Promise<void> {
|
|
await BrowserApi.executeScriptInTab(sender.tab.id, {
|
|
file: "content/fido2/content-script.js",
|
|
frameId: sender.frameId,
|
|
runAt: "document_start",
|
|
});
|
|
}
|
|
}
|