From 5de07b9a96ac8c939e36056da6af42d2875eea3c Mon Sep 17 00:00:00 2001 From: Su-Yong Date: Fri, 14 Feb 2025 21:23:19 +0900 Subject: [PATCH] fix(downloader): fix pmd undefined --- src/plugins/downloader/main/index.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/plugins/downloader/main/index.ts b/src/plugins/downloader/main/index.ts index 58737a3c..6c3a05b8 100644 --- a/src/plugins/downloader/main/index.ts +++ b/src/plugins/downloader/main/index.ts @@ -116,6 +116,11 @@ export const onMainLoad = async ({ const visitorData = yt.session.context.client.visitorData; if (visitorData) { + const cleanUp = (context: Partial) => { + delete context.window; + delete context.document; + }; + try { const [width, height] = win.getSize(); // emulate jsdom using linkedom @@ -153,16 +158,16 @@ export const onMainLoad = async ({ program: bgChallenge.program, globalName: bgChallenge.globalName, bgConfig, + }).finally(() => { + cleanUp(globalThis); }); yt.session.po_token = poTokenResult.poToken; + } else { + cleanUp(globalThis); } - } finally { - // Bypass TypeScript checks - ((x: Partial) => { - delete x.window; - delete x.document; - })(globalThis); + } catch { + cleanUp(globalThis); } }