better proxy handling

This commit is contained in:
Fabian Freund
2025-02-21 11:55:24 +01:00
parent a9cad61d36
commit a512e5c808
2 changed files with 42 additions and 37 deletions
@@ -55,8 +55,8 @@ export default class BackgroundMain {
) )
} }
// TODO: Fix in @types/firefox-webext-browser
async onRequest(requestDetails: Pick<_OnRequestDetails, 'cookieStoreId' | 'url' | 'tabId'>): Promise<DoNotProxy | ProxyInfo[]> { async onRequest(requestDetails: Pick<_OnRequestDetails, 'cookieStoreId' | 'url' | 'tabId'>): Promise<DoNotProxy | ProxyInfo[]> {
if (requestDetails.tabId > -1) {
const tab = (await browser.tabs.get(requestDetails.tabId)) const tab = (await browser.tabs.get(requestDetails.tabId))
if (tab.cookieStoreId?.startsWith(containerIdentifier) === true) { if (tab.cookieStoreId?.startsWith(containerIdentifier) === true) {
@@ -65,6 +65,10 @@ export default class BackgroundMain {
const proxies = await this.store.getProxiesForContainer(cookieStoreId) const proxies = await this.store.getProxiesForContainer(cookieStoreId)
if (proxies === null) {
return doNotProxy
}
if (proxies.length > 0) { if (proxies.length > 0) {
proxies.forEach(p => { proxies.forEach(p => {
if (p.type === ProxyType.Http || p.type === ProxyType.Https) { if (p.type === ProxyType.Http || p.type === ProxyType.Https) {
@@ -98,6 +102,7 @@ export default class BackgroundMain {
return [emergencyBreak] return [emergencyBreak]
} }
} }
}
return doNotProxy return doNotProxy
} }
@@ -119,13 +119,13 @@ export class Store {
} }
} }
async getProxiesForContainer(cookieStoreId: string): Promise<ProxySettings[]> { async getProxiesForContainer(cookieStoreId: string): Promise<ProxySettings[] | null> {
const relations = await this.getRelations() const relations = await this.getRelations()
const proxyIds: string[] = relations[cookieStoreId] ?? [] const proxyIds: string[] = relations[cookieStoreId] ?? []
if (proxyIds.length === 0) { if (proxyIds.length === 0) {
return [] return null
} }
const proxies = await this.getAllProxies() const proxies = await this.getAllProxies()