feat: Enhance Step 9 diagnostics and error handling
- Refactor getStatusBadgeEntries to use createStep9Entry for better encapsulation. - Introduce error visual signals detection in createStep9Entry. - Add functions to identify OAuth callback timeout failures and step 9 failure texts. - Update buildStep9StatusDiagnostics to include error visual summaries and handle conflicts between success and failure states. - Implement new tests for step 9 diagnostics, ensuring correct behavior with success badges and error banners. - Remove outdated tests related to step 5 onboarding and redirect race conditions. - Add new tests for auto-run behavior in step 6 restart scenarios.
This commit is contained in:
@@ -38,12 +38,16 @@
|
||||
}
|
||||
|
||||
function isRecoverableStep9AuthFailure(statusText) {
|
||||
const text = String(statusText || '').trim();
|
||||
if (!/认证失败:\s*/i.test(text)) {
|
||||
const text = String(statusText || '').replace(/\s+/g, ' ').trim();
|
||||
if (!text) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return /timeout waiting for oauth callback|status code 5\d{2}|bad gateway|gateway timeout|temporarily unavailable/i.test(text);
|
||||
if (/oauth flow is not pending/i.test(text)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return /(?:认证失败|回调 URL 提交失败):\s*/i.test(text);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -22,7 +22,6 @@ if (document.documentElement.getAttribute(SIGNUP_PAGE_LISTENER_SENTINEL) !== '1'
|
||||
|| message.type === 'RESEND_VERIFICATION_CODE'
|
||||
|| message.type === 'ENSURE_SIGNUP_ENTRY_READY'
|
||||
|| message.type === 'ENSURE_SIGNUP_PASSWORD_PAGE_READY'
|
||||
|| message.type === 'CHATGPT_SKIP_ONBOARDING'
|
||||
) {
|
||||
resetStopState();
|
||||
handleCommand(message).then((result) => {
|
||||
@@ -84,8 +83,6 @@ async function handleCommand(message) {
|
||||
return getStep8State();
|
||||
case 'STEP8_TRIGGER_CONTINUE':
|
||||
return await step8_triggerContinue(message.payload);
|
||||
case 'CHATGPT_SKIP_ONBOARDING':
|
||||
return await skipChatgptOnboarding();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,8 +100,6 @@ const VERIFICATION_CODE_INPUT_SELECTOR = [
|
||||
const ONE_TIME_CODE_LOGIN_PATTERN = /使用一次性验证码登录|改用(?:一次性)?验证码(?:登录)?|使用验证码登录|一次性验证码|验证码登录|one[-\s]*time\s*(?:passcode|password|code)|use\s+(?:a\s+)?one[-\s]*time\s*(?:passcode|password|code)(?:\s+instead)?|use\s+(?:a\s+)?code(?:\s+instead)?|sign\s+in\s+with\s+(?:email|code)|email\s+(?:me\s+)?(?:a\s+)?code/i;
|
||||
|
||||
const RESEND_VERIFICATION_CODE_PATTERN = /重新发送(?:验证码)?|再次发送(?:验证码)?|重发(?:验证码)?|未收到(?:验证码|邮件)|resend(?:\s+code)?|send\s+(?:a\s+)?new\s+code|send\s+(?:it\s+)?again|request\s+(?:a\s+)?new\s+code|didn'?t\s+receive/i;
|
||||
const CHATGPT_ONBOARDING_TEXT_PATTERN = /welcome\s+to\s+chatgpt|what\s+should\s+chatgpt\s+call\s+you|how\s+do\s+you\s+want\s+chatgpt\s+to\s+respond|tell\s+chatgpt\s+what\s+traits|personal(?:ize|ise)\s+your\s+experience|介绍一下你自己|ChatGPT 应该如何称呼你|你希望 ChatGPT 如何回应/i;
|
||||
const CHATGPT_HOME_TEXT_PATTERN = /new\s+chat|temporary\s+chat|message\s+chatgpt|send\s+a\s+message|chatgpt\s+can\s+make\s+mistakes|新建聊天|临时聊天|给\s*ChatGPT\s*发消息|ChatGPT\s*可能会犯错/i;
|
||||
|
||||
function isVisibleElement(el) {
|
||||
if (!el) return false;
|
||||
@@ -780,69 +775,6 @@ function getStep5ErrorText() {
|
||||
return messages.find((text) => STEP5_SUBMIT_ERROR_PATTERN.test(text)) || '';
|
||||
}
|
||||
|
||||
function isChatgptOnboardingPage() {
|
||||
if (!isChatgptUrl()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (findChatgptSkipButton()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return CHATGPT_ONBOARDING_TEXT_PATTERN.test(getPageTextSnapshot());
|
||||
}
|
||||
|
||||
function isChatgptUrl(rawUrl = location.href) {
|
||||
return /(^https?:\/\/)?([^.]+\.)?chatgpt\.com(?::\d+)?/i.test(rawUrl || '');
|
||||
}
|
||||
|
||||
function hasVisibleElementMatchingSelector(selector) {
|
||||
return Array.from(document.querySelectorAll(selector)).some(isVisibleElement);
|
||||
}
|
||||
|
||||
function isChatgptAuthenticatedHomePage() {
|
||||
if (!isChatgptUrl()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isChatgptOnboardingPage()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const appShellSelectors = [
|
||||
'textarea[placeholder*="Message" i]',
|
||||
'textarea[aria-label*="Message" i]',
|
||||
'[data-testid="composer-root"]',
|
||||
'[data-testid="history-and-skills"]',
|
||||
'button[aria-label*="New chat" i]',
|
||||
'a[aria-label*="New chat" i]',
|
||||
'a[href^="/c/"]',
|
||||
];
|
||||
if (appShellSelectors.some((selector) => hasVisibleElementMatchingSelector(selector))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return CHATGPT_HOME_TEXT_PATTERN.test(getPageTextSnapshot());
|
||||
}
|
||||
|
||||
async function waitForChatgptPostSignupState(timeout = 15000) {
|
||||
const start = Date.now();
|
||||
while (Date.now() - start < timeout) {
|
||||
throwIfStopped();
|
||||
|
||||
if (isChatgptOnboardingPage()) {
|
||||
return 'onboarding';
|
||||
}
|
||||
|
||||
if (isChatgptAuthenticatedHomePage()) {
|
||||
return 'home';
|
||||
}
|
||||
|
||||
await sleep(300);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function isSignupPasswordPage() {
|
||||
return /\/create-account\/password(?:[/?#]|$)/i.test(location.pathname || '');
|
||||
@@ -2208,86 +2140,3 @@ async function step5_fillNameBirthday(payload) {
|
||||
return completionPayload;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// ChatGPT Onboarding: Skip buttons after signup redirect
|
||||
// ============================================================
|
||||
|
||||
function findChatgptSkipButton() {
|
||||
// Look for buttons containing "Skip" or "跳过" text with btn-ghost class
|
||||
const buttons = document.querySelectorAll('button');
|
||||
for (const btn of buttons) {
|
||||
if (!isVisibleElement(btn)) continue;
|
||||
const text = (btn.textContent || '').trim();
|
||||
if (/^(skip|跳过)$/i.test(text) && /btn-ghost/i.test(btn.className)) {
|
||||
return btn;
|
||||
}
|
||||
}
|
||||
// Fallback: look for any button matching skip text without class constraint
|
||||
for (const btn of buttons) {
|
||||
if (!isVisibleElement(btn)) continue;
|
||||
const text = (btn.textContent || '').trim();
|
||||
if (/^(skip|跳过)$/i.test(text)) {
|
||||
return btn;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function waitForChatgptSkipButton(timeout = 15000) {
|
||||
const start = Date.now();
|
||||
while (Date.now() - start < timeout) {
|
||||
throwIfStopped();
|
||||
const btn = findChatgptSkipButton();
|
||||
if (btn && isVisibleElement(btn)) {
|
||||
return btn;
|
||||
}
|
||||
await sleep(300);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function skipChatgptOnboarding() {
|
||||
log('ChatGPT 页面:正在确认是引导页还是已登录主页...');
|
||||
|
||||
const initialState = await waitForChatgptPostSignupState(15000);
|
||||
if (initialState === 'home') {
|
||||
log('ChatGPT 页面:未出现可跳过引导,已进入登录后的 ChatGPT 页面,按注册成功处理。', 'ok');
|
||||
return { success: true, alreadyCompleted: true };
|
||||
}
|
||||
|
||||
if (initialState !== 'onboarding') {
|
||||
throw new Error('ChatGPT 页面:未检测到可跳过引导,也未确认进入登录后的主页。URL: ' + location.href);
|
||||
}
|
||||
|
||||
log('ChatGPT 引导页:正在查找第一个"Skip/跳过"按钮...');
|
||||
|
||||
// Find first Skip button: sibling of "Next" button, with btn-ghost class
|
||||
const firstSkipBtn = await waitForChatgptSkipButton(15000);
|
||||
if (!firstSkipBtn) {
|
||||
throw new Error('ChatGPT 引导页:未找到第一个"Skip/跳过"按钮。URL: ' + location.href);
|
||||
}
|
||||
|
||||
await humanPause(500, 1200);
|
||||
simulateClick(firstSkipBtn);
|
||||
log('ChatGPT 引导页:已点击第一个"Skip/跳过"按钮,等待第二个按钮出现...');
|
||||
|
||||
// Wait 3 seconds for the second skip button to appear
|
||||
await sleep(3000);
|
||||
|
||||
// Find second Skip button: sibling of "Continue" button, with btn-ghost class
|
||||
const secondSkipBtn = await waitForChatgptSkipButton(5000);
|
||||
if (!secondSkipBtn) {
|
||||
if (isChatgptAuthenticatedHomePage()) {
|
||||
log('ChatGPT 引导页:未找到第二个"Skip/跳过"按钮,但页面已进入登录后的 ChatGPT 页面。', 'ok');
|
||||
} else {
|
||||
log('ChatGPT 引导页:5秒内未找到第二个"Skip/跳过"按钮,判定注册已完成。', 'ok');
|
||||
}
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
await humanPause(500, 1200);
|
||||
simulateClick(secondSkipBtn);
|
||||
log('ChatGPT 引导页:已点击第二个"Skip/跳过"按钮,注册流程完成。', 'ok');
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
+212
-33
@@ -208,13 +208,7 @@ function getStatusBadgeEntries() {
|
||||
for (const candidate of candidates) {
|
||||
if (seen.has(candidate)) continue;
|
||||
seen.add(candidate);
|
||||
entries.push({
|
||||
element: candidate,
|
||||
selector,
|
||||
visible: isVisibleElement(candidate),
|
||||
text: (candidate.textContent || '').replace(/\s+/g, ' ').trim(),
|
||||
className: String(candidate.className || '').replace(/\s+/g, ' ').trim(),
|
||||
});
|
||||
entries.push(createStep9Entry(candidate, selector));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +221,8 @@ function summarizeStatusBadgeEntries(entries) {
|
||||
.map((entry, index) => {
|
||||
const text = entry.text || '(空文本)';
|
||||
const className = entry.className ? ` class=${getInlineTextSnippet(entry.className, 80)}` : '';
|
||||
return `#${index + 1}="${getInlineTextSnippet(text, 80)}"${className}`;
|
||||
const errorVisual = entry.errorVisualSummary ? ` error=${getInlineTextSnippet(entry.errorVisualSummary, 80)}` : '';
|
||||
return `#${index + 1}="${getInlineTextSnippet(text, 80)}"${className}${errorVisual}`;
|
||||
})
|
||||
.join(' | ');
|
||||
}
|
||||
@@ -242,6 +237,20 @@ function normalizeStep9StatusText(statusText) {
|
||||
return String(statusText || '').replace(/\s+/g, ' ').trim();
|
||||
}
|
||||
|
||||
function isOAuthCallbackTimeoutFailure(statusText) {
|
||||
return /认证失败:\s*(?:Timeout waiting for OAuth callback|timeout of \d+ms exceeded)/i.test(statusText || '');
|
||||
}
|
||||
|
||||
function isStep9FailureText(statusText) {
|
||||
const text = normalizeStep9StatusText(statusText);
|
||||
if (!text) return false;
|
||||
if (isOAuthCallbackTimeoutFailure(text)) return true;
|
||||
if (typeof isRecoverableStep9AuthFailure === 'function' && isRecoverableStep9AuthFailure(text)) {
|
||||
return true;
|
||||
}
|
||||
return /回调\s*url\s*提交失败|callback\s*url\s*submit\s*failed|oauth flow is not pending/i.test(text);
|
||||
}
|
||||
|
||||
function isStep9SuccessStatus(statusText) {
|
||||
return STEP9_SUCCESS_STATUSES.has(normalizeStep9StatusText(statusText));
|
||||
}
|
||||
@@ -251,37 +260,188 @@ function isStep9SuccessLikeStatus(statusText) {
|
||||
return /authentication successful|аутентификац.*успеш|认证成功/i.test(text);
|
||||
}
|
||||
|
||||
function getStatusBadgeDiagnostics() {
|
||||
const entries = getStatusBadgeEntries();
|
||||
function parseCssColorChannels(colorText) {
|
||||
const text = String(colorText || '').trim().toLowerCase();
|
||||
if (!text || text === 'transparent' || text === 'inherit' || text === 'initial' || text === 'unset') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (text.startsWith('#')) {
|
||||
const hex = text.slice(1);
|
||||
if (hex.length === 3 || hex.length === 4) {
|
||||
const expanded = hex.split('').map((part) => part + part);
|
||||
const [r, g, b, a = 'ff'] = expanded;
|
||||
return {
|
||||
r: Number.parseInt(r, 16),
|
||||
g: Number.parseInt(g, 16),
|
||||
b: Number.parseInt(b, 16),
|
||||
a: Number.parseInt(a, 16) / 255,
|
||||
};
|
||||
}
|
||||
if (hex.length === 6 || hex.length === 8) {
|
||||
const parts = hex.match(/.{1,2}/g) || [];
|
||||
const [r, g, b, a = 'ff'] = parts;
|
||||
return {
|
||||
r: Number.parseInt(r, 16),
|
||||
g: Number.parseInt(g, 16),
|
||||
b: Number.parseInt(b, 16),
|
||||
a: Number.parseInt(a, 16) / 255,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (text.startsWith('rgb')) {
|
||||
const numericParts = text.match(/[\d.]+/g) || [];
|
||||
if (numericParts.length >= 3) {
|
||||
const [r, g, b, a = '1'] = numericParts.map(Number);
|
||||
return { r, g, b, a };
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function isReddishColor(colorText) {
|
||||
const channels = parseCssColorChannels(colorText);
|
||||
if (!channels) return false;
|
||||
const { r, g, b, a = 1 } = channels;
|
||||
if (a <= 0.05) return false;
|
||||
return r >= 120 && r >= g + 35 && r >= b + 35;
|
||||
}
|
||||
|
||||
function getStep9ErrorVisualSignals(element, className = '') {
|
||||
const signals = [];
|
||||
const normalizedClassName = String(className || '').replace(/\s+/g, ' ').trim();
|
||||
if (/(?:error|danger|fail|destructive|text-red|text-danger|alert)/i.test(normalizedClassName)) {
|
||||
signals.push(`class=${getInlineTextSnippet(normalizedClassName, 80)}`);
|
||||
}
|
||||
|
||||
if (!element) {
|
||||
return signals;
|
||||
}
|
||||
|
||||
const style = window.getComputedStyle(element);
|
||||
if (isReddishColor(style.color)) {
|
||||
signals.push(`color=${style.color}`);
|
||||
}
|
||||
if (isReddishColor(style.borderColor)) {
|
||||
signals.push(`border=${style.borderColor}`);
|
||||
}
|
||||
if (isReddishColor(style.backgroundColor)) {
|
||||
signals.push(`background=${style.backgroundColor}`);
|
||||
}
|
||||
|
||||
return signals;
|
||||
}
|
||||
|
||||
function createStep9Entry(candidate, selector) {
|
||||
const className = String(candidate?.className || '').replace(/\s+/g, ' ').trim();
|
||||
const errorVisualSignals = getStep9ErrorVisualSignals(candidate, className);
|
||||
return {
|
||||
element: candidate,
|
||||
selector,
|
||||
visible: isVisibleElement(candidate),
|
||||
text: normalizeStep9StatusText(candidate?.textContent || ''),
|
||||
className,
|
||||
errorVisualSignals,
|
||||
errorVisualSummary: errorVisualSignals.join(', '),
|
||||
hasErrorVisualSignal: errorVisualSignals.length > 0,
|
||||
};
|
||||
}
|
||||
|
||||
function getStep9PageErrorSelectors() {
|
||||
return [
|
||||
'[role="alert"]',
|
||||
'[aria-live="assertive"]',
|
||||
'[aria-live="polite"]',
|
||||
'.alert',
|
||||
'[class*="alert"]',
|
||||
'[class*="error"]',
|
||||
'[class*="danger"]',
|
||||
'.text-danger',
|
||||
'.text-red',
|
||||
];
|
||||
}
|
||||
|
||||
function getStep9PageErrorEntries() {
|
||||
const seen = new Set();
|
||||
const entries = [];
|
||||
|
||||
for (const selector of getStep9PageErrorSelectors()) {
|
||||
const candidates = document.querySelectorAll(selector);
|
||||
for (const candidate of candidates) {
|
||||
if (seen.has(candidate)) continue;
|
||||
seen.add(candidate);
|
||||
if (!isVisibleElement(candidate)) continue;
|
||||
|
||||
const entry = createStep9Entry(candidate, selector);
|
||||
if (!isStep9FailureText(entry.text)) continue;
|
||||
entries.push(entry);
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
function buildStep9StatusDiagnostics(entries = [], pageErrorEntries = [], pageSnippet = '') {
|
||||
const visibleEntries = entries.filter((entry) => entry.visible);
|
||||
const selectedEntry = visibleEntries[0] || null;
|
||||
const selectedText = selectedEntry?.text || '';
|
||||
const successLikeEntries = visibleEntries.filter((entry) => isStep9SuccessLikeStatus(entry.text));
|
||||
const exactSuccessEntries = visibleEntries.filter((entry) => isStep9SuccessStatus(entry.text));
|
||||
const exactSuccessEntries = visibleEntries.filter((entry) => isStep9SuccessStatus(entry.text) && !entry.hasErrorVisualSignal);
|
||||
const failureEntries = visibleEntries.filter((entry) => isStep9FailureText(entry.text));
|
||||
const errorStyledEntries = visibleEntries.filter((entry) => entry.hasErrorVisualSignal);
|
||||
const allFailureEntries = [...failureEntries, ...pageErrorEntries];
|
||||
const decisiveFailureEntry = allFailureEntries[0] || null;
|
||||
const selectedEntry = decisiveFailureEntry || exactSuccessEntries[0] || visibleEntries[0] || null;
|
||||
const selectedText = selectedEntry?.text || '';
|
||||
const visibleSummary = summarizeStatusBadgeEntries(visibleEntries);
|
||||
const pageSnippet = getPageTextSnippet();
|
||||
const successLikeSummary = summarizeStatusBadgeEntries(successLikeEntries);
|
||||
const exactSuccessSummary = summarizeStatusBadgeEntries(exactSuccessEntries);
|
||||
const failureSummary = summarizeStatusBadgeEntries(failureEntries);
|
||||
const pageErrorSummary = summarizeStatusBadgeEntries(pageErrorEntries);
|
||||
const errorStyledSummary = summarizeStatusBadgeEntries(errorStyledEntries);
|
||||
const extraFailureSuffix = pageErrorEntries.length ? `;额外错误提示:${pageErrorSummary}` : '';
|
||||
const errorStyledSuffix = errorStyledEntries.length ? `;红色/错误样式徽标:${errorStyledSummary}` : '';
|
||||
|
||||
return {
|
||||
selectedText,
|
||||
exactSuccessText: exactSuccessEntries[0]?.text || '',
|
||||
failureText: decisiveFailureEntry?.text || '',
|
||||
visibleCount: visibleEntries.length,
|
||||
visibleSummary,
|
||||
hasSuccessLikeVisibleBadge: successLikeEntries.length > 0,
|
||||
hasExactSuccessVisibleBadge: exactSuccessEntries.length > 0,
|
||||
successLikeSummary: summarizeStatusBadgeEntries(successLikeEntries),
|
||||
exactSuccessSummary: summarizeStatusBadgeEntries(exactSuccessEntries),
|
||||
hasFailureVisibleBadge: allFailureEntries.length > 0,
|
||||
hasErrorStyledVisibleBadge: errorStyledEntries.length > 0,
|
||||
successLikeSummary,
|
||||
exactSuccessSummary,
|
||||
failureSummary,
|
||||
pageErrorSummary,
|
||||
errorStyledSummary,
|
||||
pageSnippet,
|
||||
signature: JSON.stringify({
|
||||
selectedText,
|
||||
visibleCount: visibleEntries.length,
|
||||
visibleSummary,
|
||||
successLikeSummary: summarizeStatusBadgeEntries(successLikeEntries),
|
||||
successLikeSummary,
|
||||
exactSuccessSummary,
|
||||
failureSummary,
|
||||
pageErrorSummary,
|
||||
errorStyledSummary,
|
||||
}),
|
||||
summary: selectedText
|
||||
? `当前选中徽标="${getInlineTextSnippet(selectedText, 80)}";可见徽标 ${visibleEntries.length} 个:${visibleSummary}`
|
||||
: `当前未选中任何可见状态徽标;可见徽标 ${visibleEntries.length} 个:${visibleSummary};页面片段="${getInlineTextSnippet(pageSnippet, 120)}"`,
|
||||
? `当前聚焦状态="${getInlineTextSnippet(selectedText, 80)}";可见徽标 ${visibleEntries.length} 个:${visibleSummary}${extraFailureSuffix}${errorStyledSuffix}`
|
||||
: `当前未选中任何可见状态徽标;可见徽标 ${visibleEntries.length} 个:${visibleSummary}${extraFailureSuffix}${errorStyledSuffix};页面片段="${getInlineTextSnippet(pageSnippet, 120)}"`,
|
||||
};
|
||||
}
|
||||
|
||||
function getStatusBadgeDiagnostics() {
|
||||
return buildStep9StatusDiagnostics(
|
||||
getStatusBadgeEntries(),
|
||||
getStep9PageErrorEntries(),
|
||||
getPageTextSnippet()
|
||||
);
|
||||
}
|
||||
|
||||
function getStatusBadgeElement() {
|
||||
const visibleEntry = getStatusBadgeEntries().find((entry) => entry.visible);
|
||||
return visibleEntry ? visibleEntry.element : null;
|
||||
@@ -292,20 +452,16 @@ function getStatusBadgeText() {
|
||||
return diagnostics.selectedText;
|
||||
}
|
||||
|
||||
function isOAuthCallbackTimeoutFailure(statusText) {
|
||||
return /认证失败:\s*Timeout waiting for OAuth callback/i.test(statusText || '');
|
||||
}
|
||||
|
||||
async function waitForExactSuccessBadge(timeout = STEP9_SUCCESS_BADGE_TIMEOUT_MS) {
|
||||
const start = Date.now();
|
||||
let lastDiagnosticsSignature = '';
|
||||
let lastHeartbeatLoggedAt = 0;
|
||||
let lastSuccessLikeMismatchSignature = '';
|
||||
let lastSuccessFailureConflictSignature = '';
|
||||
|
||||
while (Date.now() - start < timeout) {
|
||||
throwIfStopped();
|
||||
const diagnostics = getStatusBadgeDiagnostics();
|
||||
const statusText = diagnostics.selectedText;
|
||||
const elapsed = Date.now() - start;
|
||||
|
||||
if (diagnostics.signature !== lastDiagnosticsSignature) {
|
||||
@@ -324,36 +480,59 @@ async function waitForExactSuccessBadge(timeout = STEP9_SUCCESS_BADGE_TIMEOUT_MS
|
||||
selectedText: diagnostics.selectedText,
|
||||
successLikeSummary: diagnostics.successLikeSummary,
|
||||
visibleSummary: diagnostics.visibleSummary,
|
||||
errorStyledSummary: diagnostics.errorStyledSummary,
|
||||
});
|
||||
if (mismatchSignature !== lastSuccessLikeMismatchSignature) {
|
||||
lastSuccessLikeMismatchSignature = mismatchSignature;
|
||||
const errorStyledSuffix = diagnostics.hasErrorStyledVisibleBadge
|
||||
? `;错误样式徽标:${diagnostics.errorStyledSummary}`
|
||||
: '';
|
||||
log(
|
||||
`步骤 9:检测到“认证成功”相关徽标,但未命中精确条件。当前选中="${getInlineTextSnippet(diagnostics.selectedText || '(空)', 80)}";成功相关徽标:${diagnostics.successLikeSummary}`,
|
||||
`步骤 9:检测到“认证成功”相关徽标,但未命中精确成功条件。当前聚焦="${getInlineTextSnippet(diagnostics.selectedText || '(空)', 80)}";成功相关徽标:${diagnostics.successLikeSummary}${errorStyledSuffix}`,
|
||||
'warn'
|
||||
);
|
||||
console.warn(LOG_PREFIX, '[Step 9] success-like badge detected without exact match', diagnostics);
|
||||
}
|
||||
}
|
||||
|
||||
if (isOAuthCallbackTimeoutFailure(statusText)) {
|
||||
throw new Error(`STEP9_OAUTH_TIMEOUT::${statusText}`);
|
||||
if (diagnostics.hasExactSuccessVisibleBadge && diagnostics.hasFailureVisibleBadge) {
|
||||
const conflictSignature = JSON.stringify({
|
||||
exactSuccessSummary: diagnostics.exactSuccessSummary,
|
||||
failureSummary: diagnostics.failureSummary,
|
||||
pageErrorSummary: diagnostics.pageErrorSummary,
|
||||
});
|
||||
if (conflictSignature !== lastSuccessFailureConflictSignature) {
|
||||
lastSuccessFailureConflictSignature = conflictSignature;
|
||||
const failureSummary = diagnostics.pageErrorSummary !== '无可见状态徽标'
|
||||
? diagnostics.pageErrorSummary
|
||||
: diagnostics.failureSummary;
|
||||
log(
|
||||
`步骤 9:同时检测到成功徽标和失败提示,本轮不判定成功。成功徽标:${diagnostics.exactSuccessSummary};失败提示:${failureSummary}`,
|
||||
'warn'
|
||||
);
|
||||
console.warn(LOG_PREFIX, '[Step 9] success badge is blocked by visible failure', diagnostics);
|
||||
}
|
||||
}
|
||||
if (typeof isRecoverableStep9AuthFailure === 'function' && isRecoverableStep9AuthFailure(statusText)) {
|
||||
throw new Error(`STEP9_OAUTH_RETRY::${statusText}`);
|
||||
|
||||
if (diagnostics.failureText) {
|
||||
if (isOAuthCallbackTimeoutFailure(diagnostics.failureText)) {
|
||||
throw new Error(`STEP9_OAUTH_TIMEOUT::${diagnostics.failureText}`);
|
||||
}
|
||||
throw new Error(`STEP9_OAUTH_RETRY::${diagnostics.failureText}`);
|
||||
}
|
||||
if (isStep9SuccessStatus(statusText)) {
|
||||
return statusText;
|
||||
if (diagnostics.exactSuccessText) {
|
||||
return diagnostics.exactSuccessText;
|
||||
}
|
||||
await sleep(200);
|
||||
}
|
||||
|
||||
const finalDiagnostics = getStatusBadgeDiagnostics();
|
||||
const finalText = finalDiagnostics.selectedText;
|
||||
const finalText = finalDiagnostics.failureText || finalDiagnostics.selectedText;
|
||||
const diagnosticsSuffix = ` 当前诊断:${finalDiagnostics.summary}`;
|
||||
if (isOAuthCallbackTimeoutFailure(finalText)) {
|
||||
throw new Error(`STEP9_OAUTH_TIMEOUT::${finalText}${diagnosticsSuffix}`);
|
||||
}
|
||||
if (typeof isRecoverableStep9AuthFailure === 'function' && isRecoverableStep9AuthFailure(finalText)) {
|
||||
if (isStep9FailureText(finalText)) {
|
||||
throw new Error(`STEP9_OAUTH_RETRY::${finalText}${diagnosticsSuffix}`);
|
||||
}
|
||||
throw new Error(finalText
|
||||
|
||||
Reference in New Issue
Block a user