hmjz100/LinkSwift · warning · Error

提示:<br/>时间太长,我先撤下啦~

Error message

提示:<br/>时间太长,我先撤下啦~

What it means

In getLink()'s fallback authorization path, after opening the OAuth tab the script polls GM storage every second for a newly saved baidu_access_token. If no token appears within 120 seconds (attempts > 120), it clears the interval and throws this 'waited too long, giving up' error. Note: it is thrown inside a setInterval callback, so it becomes an uncaught interval error rather than rejecting the enclosing promise.

Source

Thrown at (改)网盘直链下载助手.user.js:6081

				throw new Error(e?.message || e || "[百度网盘] 获取令牌失败");
			});

			// 回退授权
			if (!token) {
				message.info("提示:<br/>稍后请在新标签页中授权助手哦~");
				base.delValue("baidu_access_token");
				await base.sleep(3300);
				GM_openInTab(config.$baidu.api.getAccessToken, { active: true, insert: true, setParent: true })
				let attempts = 0;
				const interval = setInterval(() => {
					if (base.getValue("baidu_access_token")) {
						clearInterval(interval);
						token = base.getValue("baidu_access_token")
					}
					attempts++;
					if (attempts > 120) {
						clearInterval(interval);
						throw new Error("提示:<br/>时间太长,我先撤下啦~");
					}
				}, 1000);
				return;
			}

			// 获取选择的文件列表
			const selects = this.getSelectedList();
			if (selects.length === 0) throw new Error("提示:<br/>请勾选要下载的文件哦~");

			$doc.find(".loading-popup .loading-title").html(`链接获取中`);
			$doc.find(".loading-popup .swal2-html-container").html(`<div>正在获取文件对应的下载链接~</div>`);

			let files = selects.filter(f => !f.isdir);
			const dirs = selects.filter(f => f.isdir);
			if (temp.page === "home" || temp.page === "main") {
				if (dirs.length > 0) files = files.concat(await this.getFilesList(dirs, token, files.length));
				if (!files.length) throw new Error("提示:<br/>文件夹是空的哦~");

View on GitHub (pinned to 417ea5e28a)

Solutions

  1. Complete the authorization in the opened tab promptly (within 2 minutes) and retry the download
  2. Re-run and watch that the authorization tab actually opens (disable popup blockers for the OAuth URL)
  3. Update the script — the token-capture page handler may be broken by Baidu's OAuth page changes
  4. Increase the 120-attempt timeout or convert the interval error into a promise rejection so callers can handle it
  5. Manually verify a baidu_access_token appears in userscript storage after authorizing

Example fix

// before
const interval = setInterval(() => {
  ...
  if (attempts > 120) { clearInterval(interval); throw new Error("时间太长,我先撤下啦~"); }
}, 1000);
// after
await new Promise((resolve, reject) => {
  const interval = setInterval(() => {
    const t = base.getValue("baidu_access_token");
    if (t) { clearInterval(interval); token = t; resolve(); }
    else if (++attempts > 120) { clearInterval(interval); reject(new Error("提示:<br/>时间太长,我先撤下啦~")); }
  }, 1000);
});
Defensive patterns

Strategy: try-catch

Validate before calling

// check whether the OAuth tab can be opened and a token-capture page is registered
let tab = GM_openInTab(config.$baidu.api.getAccessToken, { active: true, insert: true, setParent: true });
if (tab && tab.closed) throw new Error("授权标签页被拦截,请允许弹出窗口后重试");

Type guard

function isTokenAvailable() {
  const t = base.getValue("baidu_access_token");
  return typeof t === "string" && t.length > 0;
}

Try / catch

try {
  await startAuthorizationPolling();
} catch (e) {
  if (String(e.message).includes("时间太长")) {
    showManualAuthInstructions(); // guide user to authorize and click retry
  } else throw e;
}

Prevention

When it happens

Trigger: User does not complete Baidu authorization in the opened tab within 120 seconds, or the authorization page loads but the script's token-capture logic never writes baidu_access_token into GM storage.

Common situations: User ignores or closes the authorization tab; popup blocker prevented the tab from opening; Baidu authorization page fails to load or loops; the token-capture userscript on the OAuth page is outdated and no longer stores the token; user authorizes a different account so the capture page errors.

Related errors


AI-assisted analysis of hmjz100/LinkSwift@417ea5e28a (2026-09-02). Data as JSON: /api/errors/07dbb86fb2e657d5. Report an issue: GitHub.