(tabId, timeoutMs = 30000)
| 6114 | } |
| 6115 | |
| 6116 | async function reloadStep8ConsentPage(tabId, timeoutMs = 30000) { |
| 6117 | if (!Number.isInteger(tabId)) { |
| 6118 | throw new Error('步骤 8:缺少有效的认证页标签页,无法刷新后重试。'); |
| 6119 | } |
| 6120 | |
| 6121 | await chrome.tabs.update(tabId, { active: true }).catch(() => { }); |
| 6122 | |
| 6123 | await new Promise((resolve, reject) => { |
| 6124 | let settled = false; |
| 6125 | const timer = setTimeout(() => { |
| 6126 | if (settled) return; |
| 6127 | settled = true; |
| 6128 | chrome.tabs.onUpdated.removeListener(listener); |
| 6129 | reject(new Error('步骤 8:刷新认证页后等待页面完成加载超时。')); |
| 6130 | }, timeoutMs); |
| 6131 | |
| 6132 | const listener = (updatedTabId, changeInfo) => { |
| 6133 | if (updatedTabId !== tabId) return; |
| 6134 | if (changeInfo.status !== 'complete') return; |
| 6135 | if (settled) return; |
| 6136 | settled = true; |
| 6137 | clearTimeout(timer); |
| 6138 | chrome.tabs.onUpdated.removeListener(listener); |
| 6139 | resolve(); |
| 6140 | }; |
| 6141 | |
| 6142 | chrome.tabs.onUpdated.addListener(listener); |
| 6143 | chrome.tabs.reload(tabId, { bypassCache: false }).catch((err) => { |
| 6144 | if (settled) return; |
| 6145 | settled = true; |
| 6146 | clearTimeout(timer); |
| 6147 | chrome.tabs.onUpdated.removeListener(listener); |
| 6148 | reject(err); |
| 6149 | }); |
| 6150 | }); |
| 6151 | |
| 6152 | await ensureStep8SignupPageReady(tabId, { |
| 6153 | timeoutMs: Math.min(15000, timeoutMs), |
| 6154 | logMessage: '步骤 8:认证页刷新后内容脚本尚未就绪,正在等待页面恢复...', |
| 6155 | }); |
| 6156 | } |
| 6157 | |
| 6158 | async function waitForStep8ClickEffect(tabId, baselineUrl, timeoutMs = STEP8_CLICK_EFFECT_TIMEOUT_MS) { |
| 6159 | const start = Date.now(); |
no test coverage detected