{"record":{"id":"07dbb86fb2e657d5","repo":"hmjz100/LinkSwift","slug":"br-07dbb8","errorCode":null,"errorMessage":"提示：<br/>时间太长，我先撤下啦~","messagePattern":"提示：<br/>时间太长，我先撤下啦~","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"（改）网盘直链下载助手.user.js","lineNumber":6081,"sourceCode":"\t\t\t\tthrow new Error(e?.message || e || \"[百度网盘] 获取令牌失败\");\r\n\t\t\t});\r\n\r\n\t\t\t// 回退授权\r\n\t\t\tif (!token) {\r\n\t\t\t\tmessage.info(\"提示：<br/>稍后请在新标签页中授权助手哦~\");\r\n\t\t\t\tbase.delValue(\"baidu_access_token\");\r\n\t\t\t\tawait base.sleep(3300);\r\n\t\t\t\tGM_openInTab(config.$baidu.api.getAccessToken, { active: true, insert: true, setParent: true })\r\n\t\t\t\tlet attempts = 0;\r\n\t\t\t\tconst interval = setInterval(() => {\r\n\t\t\t\t\tif (base.getValue(\"baidu_access_token\")) {\r\n\t\t\t\t\t\tclearInterval(interval);\r\n\t\t\t\t\t\ttoken = base.getValue(\"baidu_access_token\")\r\n\t\t\t\t\t}\r\n\t\t\t\t\tattempts++;\r\n\t\t\t\t\tif (attempts > 120) {\r\n\t\t\t\t\t\tclearInterval(interval);\r\n\t\t\t\t\t\tthrow new Error(\"提示：<br/>时间太长，我先撤下啦~\");\r\n\t\t\t\t\t}\r\n\t\t\t\t}, 1000);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\t// 获取选择的文件列表\r\n\t\t\tconst selects = this.getSelectedList();\r\n\t\t\tif (selects.length === 0) throw new Error(\"提示：<br/>请勾选要下载的文件哦~\");\r\n\r\n\t\t\t$doc.find(\".loading-popup .loading-title\").html(`链接获取中`);\r\n\t\t\t$doc.find(\".loading-popup .swal2-html-container\").html(`<div>正在获取文件对应的下载链接~</div>`);\r\n\r\n\t\t\tlet files = selects.filter(f => !f.isdir);\r\n\t\t\tconst dirs = selects.filter(f => f.isdir);\r\n\t\t\tif (temp.page === \"home\" || temp.page === \"main\") {\r\n\t\t\t\tif (dirs.length > 0) files = files.concat(await this.getFilesList(dirs, token, files.length));\r\n\t\t\t\tif (!files.length) throw new Error(\"提示：<br/>文件夹是空的哦~\");\r\n\r","sourceCodeStart":6063,"sourceCodeEnd":6099,"githubUrl":"https://github.com/hmjz100/LinkSwift/blob/417ea5e28a3e1a90339710e17356e9fd22b8a34b/（改）网盘直链下载助手.user.js#L6063-L6099","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Complete the authorization in the opened tab promptly (within 2 minutes) and retry the download","Re-run and watch that the authorization tab actually opens (disable popup blockers for the OAuth URL)","Update the script — the token-capture page handler may be broken by Baidu's OAuth page changes","Increase the 120-attempt timeout or convert the interval error into a promise rejection so callers can handle it","Manually verify a baidu_access_token appears in userscript storage after authorizing"],"exampleFix":"// before\nconst interval = setInterval(() => {\n  ...\n  if (attempts > 120) { clearInterval(interval); throw new Error(\"时间太长，我先撤下啦~\"); }\n}, 1000);\n// after\nawait new Promise((resolve, reject) => {\n  const interval = setInterval(() => {\n    const t = base.getValue(\"baidu_access_token\");\n    if (t) { clearInterval(interval); token = t; resolve(); }\n    else if (++attempts > 120) { clearInterval(interval); reject(new Error(\"提示：<br/>时间太长，我先撤下啦~\")); }\n  }, 1000);\n});","handlingStrategy":"try-catch","validationCode":"// check whether the OAuth tab can be opened and a token-capture page is registered\nlet tab = GM_openInTab(config.$baidu.api.getAccessToken, { active: true, insert: true, setParent: true });\nif (tab && tab.closed) throw new Error(\"授权标签页被拦截，请允许弹出窗口后重试\");","typeGuard":"function isTokenAvailable() {\n  const t = base.getValue(\"baidu_access_token\");\n  return typeof t === \"string\" && t.length > 0;\n}","tryCatchPattern":"try {\n  await startAuthorizationPolling();\n} catch (e) {\n  if (String(e.message).includes(\"时间太长\")) {\n    showManualAuthInstructions(); // guide user to authorize and click retry\n  } else throw e;\n}","preventionTips":["Complete the Baidu authorization promptly after the tab opens (2-minute window)","Allow popups for the authorization URL so GM_openInTab succeeds","Check that the page script responsible for saving baidu_access_token is installed and up to date","Confirm after authorizing that the token actually appears in userscript storage","Refactor polling to reject the enclosing promise so callers can catch the timeout instead of it becoming an uncaught interval error"],"tags":["baidu-netdisk","oauth","timeout","userscript"],"backgroundTag":"oauth-callback-timeout","analyzedSha":"417ea5e28a3e1a90339710e17356e9fd22b8a34b","analyzedAt":"2026-09-02T18:13:32.837Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}