Skip to content

The only downloader you need. 下载器的集大成者。

fix(browser): filter prefetched muxed URLs by modal_id in Douyin strategy

XiaoYouChR5e4d5ec2b260
diff --git a/browser_extension/app/src/page-media/resolution/strategies/douyin.ts b/browser_extension/app/src/page-media/resolution/strategies/douyin.ts
index a4ce2caf..b77eb1b5 100644
--- a/browser_extension/app/src/page-media/resolution/strategies/douyin.ts
+++ b/browser_extension/app/src/page-media/resolution/strategies/douyin.ts
@@ -6,8 +6,19 @@ import type {Resolution} from "../../types";
// Until the next reel's MSE binds and correlation locks the URL, the prefetched URL is
// still provisionally owned by the previous reel's session. modal_id is what survives
// that window.
+function matchesModalId(url: string, modalId: string): boolean {
+ if (!modalId) { return true; }
+ try {
+ const vid = new URL(url).searchParams.get("__vid");
+ return !vid || vid === modalId;
+ } catch { return true; }
+}
+
export function selectDouyin(ctx: ResolveContext, findUrlsByIdHint: FindUrlsByIdHint): Resolution {
- const post = postBindAttributedUrls(ctx.clicked).filter((r) => hostEndsWith(r.url, "douyinvod.com"));
+ const modalId = ctx.pageUrl.searchParams.get("modal_id") ?? "";
+ const post = postBindAttributedUrls(ctx.clicked).filter((r) =>
+ hostEndsWith(r.url, "douyinvod.com") && matchesModalId(r.url, modalId),
+ );
if (ctx.clicked.formKind === "muxed") {
const muxed = newestMatching(post, (url) => douyinKindOf(url) === "muxed") ?? findByModalId(ctx, findUrlsByIdHint, "muxed");