bitwarden-browser/src/content/message_handler.ts

38 lines
924 B
TypeScript
Raw Normal View History

2021-12-21 15:43:35 +01:00
window.addEventListener(
"message",
(event) => {
if (event.source !== window) return;
2021-12-21 15:43:35 +01:00
if (event.data.command && event.data.command === "authResult") {
chrome.runtime.sendMessage({
command: event.data.command,
code: event.data.code,
state: event.data.state,
referrer: event.source.location.hostname,
});
}
2021-12-21 15:43:35 +01:00
if (event.data.command && event.data.command === "webAuthnResult") {
chrome.runtime.sendMessage({
command: event.data.command,
data: event.data.data,
remember: event.data.remember,
referrer: event.source.location.hostname,
});
}
2021-12-21 15:43:35 +01:00
},
false
);
2021-12-21 15:43:35 +01:00
const forwardCommands = [
"promptForLogin",
"addToLockedVaultPendingNotifications",
"unlockCompleted",
];
2021-12-21 15:43:35 +01:00
chrome.runtime.onMessage.addListener((event) => {
if (forwardCommands.includes(event.command)) {
chrome.runtime.sendMessage(event);
}
});