(state)
| 29 | } |
| 30 | |
| 31 | async function executeCpaStep9(state) { |
| 32 | if (state.localhostUrl && !isLocalhostOAuthCallbackUrl(state.localhostUrl)) { |
| 33 | throw new Error('步骤 8 捕获到的 localhost OAuth 回调地址无效,请重新执行步骤 8。'); |
| 34 | } |
| 35 | if (!state.localhostUrl) { |
| 36 | throw new Error('缺少 localhost 回调地址,请先完成步骤 8。'); |
| 37 | } |
| 38 | if (!state.vpsUrl) { |
| 39 | throw new Error('尚未填写 CPA 地址,请先在侧边栏输入。'); |
| 40 | } |
| 41 | |
| 42 | if (shouldBypassStep9ForLocalCpa(state)) { |
| 43 | await addLog('步骤 9:检测到本地 CPA,且当前策略为“跳过第9步”,本轮不再重复提交回调地址。', 'info'); |
| 44 | await completeStepFromBackground(9, { |
| 45 | localhostUrl: state.localhostUrl, |
| 46 | verifiedStatus: 'local-auto', |
| 47 | }); |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | await addLog('步骤 9:正在打开 CPA 面板...'); |
| 52 | |
| 53 | const injectFiles = ['content/activation-utils.js', 'content/utils.js', 'content/vps-panel.js']; |
| 54 | let tabId = await getTabId('vps-panel'); |
| 55 | const alive = tabId && await isTabAlive('vps-panel'); |
| 56 | |
| 57 | if (!alive) { |
| 58 | tabId = await reuseOrCreateTab('vps-panel', state.vpsUrl, { |
| 59 | inject: injectFiles, |
| 60 | reloadIfSameUrl: true, |
| 61 | }); |
| 62 | } else { |
| 63 | await closeConflictingTabsForSource('vps-panel', state.vpsUrl, { excludeTabIds: [tabId] }); |
| 64 | await chrome.tabs.update(tabId, { active: true }); |
| 65 | await rememberSourceLastUrl('vps-panel', state.vpsUrl); |
| 66 | } |
| 67 | |
| 68 | await ensureContentScriptReadyOnTab('vps-panel', tabId, { |
| 69 | inject: injectFiles, |
| 70 | timeoutMs: 45000, |
| 71 | retryDelayMs: 900, |
| 72 | logMessage: '步骤 9:CPA 面板仍在加载,正在重试连接...', |
| 73 | }); |
| 74 | |
| 75 | await addLog('步骤 9:正在填写回调地址...'); |
| 76 | const result = await sendToContentScriptResilient('vps-panel', { |
| 77 | type: 'EXECUTE_STEP', |
| 78 | step: 9, |
| 79 | source: 'background', |
| 80 | payload: { localhostUrl: state.localhostUrl, vpsPassword: state.vpsPassword }, |
| 81 | }, { |
| 82 | timeoutMs: 30000, |
| 83 | retryDelayMs: 700, |
| 84 | logMessage: '步骤 9:CPA 面板通信未就绪,正在等待页面恢复...', |
| 85 | }); |
| 86 | |
| 87 | if (result?.error) { |
| 88 | throw new Error(result.error); |
no test coverage detected