1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-11 14:04:03 +00:00

add explicit checks and change remove listener to any in order to match add listener and chrome api

This commit is contained in:
Daniel Riera
2026-01-12 15:55:34 -05:00
parent c6f704bd21
commit 9aee32d17e
2 changed files with 24 additions and 11 deletions

View File

@@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { filter, firstValueFrom, of, switchMap } from "rxjs";
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
@@ -64,6 +62,7 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr
this.policyService.policiesByType$(PolicyType.AutomaticAppLogIn, userId),
),
getFirstPolicy,
filter((policy): policy is Policy => policy !== undefined),
)
.subscribe(this.handleAutoSubmitLoginPolicySubscription.bind(this));
}
@@ -165,6 +164,9 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr
details: chrome.webRequest.OnBeforeRequestDetails,
): undefined => {
const requestInitiator = this.getRequestInitiator(details);
if (!requestInitiator) {
return;
}
const isValidInitiator = this.isValidInitiator(requestInitiator);
if (
@@ -368,8 +370,9 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr
}
const tab = await BrowserApi.getTab(details.tabId);
if (this.isValidAutoSubmitHost(tab?.url)) {
this.removeUrlFromAutoSubmitHosts(tab.url);
const tabUrl = tab?.url;
if (tabUrl && this.isValidAutoSubmitHost(tabUrl)) {
this.removeUrlFromAutoSubmitHosts(tabUrl);
}
};
@@ -495,6 +498,10 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr
message: AutoSubmitLoginMessage,
sender: chrome.runtime.MessageSender,
) => {
if (sender.frameId == null || !sender.tab || !message.pageDetails) {
return;
}
await this.autofillService.doAutoFillOnTab(
[
{
@@ -515,7 +522,9 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr
* @param sender - The message sender.
*/
private handleMultiStepAutoSubmitLoginComplete = (sender: chrome.runtime.MessageSender) => {
this.removeUrlFromAutoSubmitHosts(sender.url);
if (sender.url) {
this.removeUrlFromAutoSubmitHosts(sender.url);
}
};
/**
@@ -526,7 +535,7 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr
*/
private async initSafari() {
const currentTab = await BrowserApi.getTabFromCurrentWindow();
if (currentTab) {
if (currentTab?.url && currentTab.id !== undefined) {
this.setMostRecentIdpHost(currentTab.url, currentTab.id);
}
@@ -558,7 +567,7 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr
}
const tab = await BrowserApi.getTab(activeInfo.tabId);
if (tab) {
if (tab?.url && tab.id !== undefined) {
this.setMostRecentIdpHost(tab.url, tab.id);
}
};
@@ -570,7 +579,7 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr
* @param changeInfo - The change information of the tab.
*/
private handleSafariTabOnUpdated = (tabId: number, changeInfo: chrome.tabs.OnUpdatedInfo) => {
if (changeInfo) {
if (changeInfo && changeInfo.url) {
this.setMostRecentIdpHost(changeInfo.url, tabId);
}
};
@@ -626,13 +635,17 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr
* @param sender - The message sender.
* @param sendResponse - The response callback.
*/
private handleExtensionMessage = async (
private handleExtensionMessage = (
message: AutoSubmitLoginMessage,
sender: chrome.runtime.MessageSender,
sendResponse: (response?: any) => void,
) => {
const { tab, url } = sender;
if (tab?.id !== this.currentAutoSubmitHostData.tabId || !this.isValidAutoSubmitHost(url)) {
if (
!url ||
tab?.id !== this.currentAutoSubmitHostData.tabId ||
!this.isValidAutoSubmitHost(url)
) {
return null;
}

View File

@@ -560,7 +560,7 @@ export class BrowserApi {
* @param event - The event in which to remove the listener from.
* @param callback - The callback you want removed from the event.
*/
static removeListener<T extends (...args: readonly unknown[]) => unknown>(
static removeListener<T extends (...args: readonly any[]) => any>(
event: chrome.events.Event<T>,
callback: T,
) {