The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
fix(extension): 拦截下载丢失 cookie 导致需要登录的站点下载出网页
XiaoYouChR68106720c565
diff --git a/browser_extension/app/src/background.ts b/browser_extension/app/src/background.tsindex f811ee34..cf2c94df 100644--- a/browser_extension/app/src/background.ts+++ b/browser_extension/app/src/background.ts@@ -257,22 +257,24 @@ chrome.runtime.onInstalled.addListener(() => {});chrome.contextMenus.onClicked.addListener((info) => {- const url = info.linkUrl || info.srcUrl;- if (!url) { return; }- const draft = info.menuItemId === "gd-save-as";- const headers = resourceBridge.headersForPage(info.pageUrl ?? "");- if (!headers.referer && info.pageUrl) {- headers.referer = info.pageUrl;- }- void sendTaskOrEnqueue({- type: "create_task",- source: "download",- draft,- title: "",- payload: { url, headers, filename: "", size: 0, supportsRange: false },- }).then((result) => {+ void (async () => {+ await ready;+ const url = info.linkUrl || info.srcUrl;+ if (!url) { return; }+ const draft = info.menuItemId === "gd-save-as";+ const headers = resourceBridge.headersForPage(info.pageUrl ?? "");+ if (!headers.referer && info.pageUrl) {+ headers.referer = info.pageUrl;+ }+ const result = await sendTaskOrEnqueue({+ type: "create_task",+ source: "download",+ draft,+ title: "",+ payload: { url, headers, filename: "", size: 0, supportsRange: false },+ });if (result.ok && shouldOpenPopupOnSent) { void openActionPopup(); }- });+ })();});chrome.alarms.onAlarm.addListener((alarm) => {diff --git a/browser_extension/app/src/background/resource-bridge.ts b/browser_extension/app/src/background/resource-bridge.tsindex c8c7bc8f..89ad4846 100644--- a/browser_extension/app/src/background/resource-bridge.ts+++ b/browser_extension/app/src/background/resource-bridge.ts@@ -308,7 +308,10 @@ export function createResourceBridge(options: {headers: bridgeState[BRIDGE_HEADER_SNAPSHOTS_KEY] ?? [],});- lastActiveTabId = Number(bridgeState[BRIDGE_LAST_ACTIVE_TAB_KEY] ?? 0) || null;+ const storedTabId = Number(bridgeState[BRIDGE_LAST_ACTIVE_TAB_KEY] ?? 0) || null;+ if (lastActiveTabId === null) {+ lastActiveTabId = storedTabId;+ }loadedFromStorage = true;}diff --git a/browser_extension/app/src/background/resource-cache.ts b/browser_extension/app/src/background/resource-cache.tsindex 874342a5..c09bf2cd 100644--- a/browser_extension/app/src/background/resource-cache.ts+++ b/browser_extension/app/src/background/resource-cache.ts@@ -373,6 +373,12 @@ export class ResourceCache {}load(snapshot: ResourceCacheSnapshot): void {+ // Event handlers (onSendHeaders, onResponseStarted) may have written to the+ // cache between service-worker start and this load call. Preserve those+ // in-flight entries — they are always fresher than stored data.+ const inFlightResources = new Map(this.resourcesById);+ const inFlightHeaders = new Map(this.headerSnapshotsByUrl);+this.resourcesByTab.clear();this.resourcesById.clear();for (const [tabIdText, resources] of Object.entries(snapshot.resources ?? {})) {@@ -388,6 +394,19 @@ export class ResourceCache {this.resourcesByTab.set(tabId, resourceMap);}+ for (const [id, inFlight] of inFlightResources) {+ const stored = this.resourcesById.get(id);+ if (!stored || inFlight.capturedAt > stored.capturedAt) {+ let tabMap = this.resourcesByTab.get(inFlight.tabId);+ if (!tabMap) {+ tabMap = new Map<string, Resource>();+ this.resourcesByTab.set(inFlight.tabId, tabMap);+ }+ tabMap.set(id, inFlight);+ this.resourcesById.set(id, inFlight);+ }+ }+this.headerSnapshotsByUrl.clear();for (const snapshotHeader of snapshot.headers ?? []) {const normalized = headerSnapshotFromStorage(snapshotHeader);@@ -396,6 +415,14 @@ export class ResourceCache {}this.headerSnapshotsByUrl.set(normalized.url, normalized);}++ for (const [url, inFlight] of inFlightHeaders) {+ const stored = this.headerSnapshotsByUrl.get(url);+ if (!stored || inFlight.capturedAt > stored.capturedAt) {+ this.headerSnapshotsByUrl.set(url, inFlight);+ }+ }+this.removeStaleHeaders();}