signup-page.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. // content/signup-page.js — Content script for OpenAI auth pages (steps 2, 3, 4-receive, 5)
  2. // Injected on: auth0.openai.com, auth.openai.com, accounts.openai.com
  3. console.log('[MultiPage:signup-page] Content script loaded on', location.href);
  4. // Listen for commands from Background
  5. chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
  6. if (
  7. message.type === 'EXECUTE_STEP'
  8. || message.type === 'FILL_CODE'
  9. || message.type === 'STEP8_FIND_AND_CLICK'
  10. || message.type === 'PREPARE_LOGIN_CODE'
  11. || message.type === 'PREPARE_SIGNUP_VERIFICATION'
  12. || message.type === 'RESEND_VERIFICATION_CODE'
  13. ) {
  14. resetStopState();
  15. handleCommand(message).then((result) => {
  16. sendResponse({ ok: true, ...(result || {}) });
  17. }).catch(err => {
  18. if (isStopError(err)) {
  19. log(`步骤 ${message.step || 8}:已被用户停止。`, 'warn');
  20. sendResponse({ stopped: true, error: err.message });
  21. return;
  22. }
  23. if (message.type === 'STEP8_FIND_AND_CLICK') {
  24. log(`步骤 8:${err.message}`, 'error');
  25. sendResponse({ error: err.message });
  26. return;
  27. }
  28. reportError(message.step, err.message);
  29. sendResponse({ error: err.message });
  30. });
  31. return true;
  32. }
  33. });
  34. async function handleCommand(message) {
  35. switch (message.type) {
  36. case 'EXECUTE_STEP':
  37. switch (message.step) {
  38. case 2: return await step2_clickRegister();
  39. case 3: return await step3_fillEmailPassword(message.payload);
  40. case 5: return await step5_fillNameBirthday(message.payload);
  41. case 6: return await step6_login(message.payload);
  42. case 8: return await step8_findAndClick();
  43. default: throw new Error(`signup-page.js 不处理步骤 ${message.step}`);
  44. }
  45. case 'FILL_CODE':
  46. // Step 4 = signup code, Step 7 = login code (same handler)
  47. return await fillVerificationCode(message.step, message.payload);
  48. case 'PREPARE_SIGNUP_VERIFICATION':
  49. return await prepareSignupVerificationFlow(message.payload);
  50. case 'PREPARE_LOGIN_CODE':
  51. return await prepareLoginCodeFlow();
  52. case 'RESEND_VERIFICATION_CODE':
  53. return await resendVerificationCode(message.step);
  54. case 'STEP8_FIND_AND_CLICK':
  55. return await step8_findAndClick();
  56. }
  57. }
  58. const VERIFICATION_CODE_INPUT_SELECTOR = [
  59. 'input[name="code"]',
  60. 'input[name="otp"]',
  61. 'input[autocomplete="one-time-code"]',
  62. 'input[type="text"][maxlength="6"]',
  63. 'input[type="tel"][maxlength="6"]',
  64. 'input[aria-label*="code" i]',
  65. 'input[placeholder*="code" i]',
  66. 'input[inputmode="numeric"]',
  67. ].join(', ');
  68. 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;
  69. 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;
  70. function isVisibleElement(el) {
  71. if (!el) return false;
  72. const style = window.getComputedStyle(el);
  73. const rect = el.getBoundingClientRect();
  74. return style.display !== 'none'
  75. && style.visibility !== 'hidden'
  76. && rect.width > 0
  77. && rect.height > 0;
  78. }
  79. function getVerificationCodeTarget() {
  80. const codeInput = document.querySelector(VERIFICATION_CODE_INPUT_SELECTOR);
  81. if (codeInput && isVisibleElement(codeInput)) {
  82. return { type: 'single', element: codeInput };
  83. }
  84. const singleInputs = Array.from(document.querySelectorAll('input[maxlength="1"]'))
  85. .filter(isVisibleElement);
  86. if (singleInputs.length >= 6) {
  87. return { type: 'split', elements: singleInputs };
  88. }
  89. return null;
  90. }
  91. function getActionText(el) {
  92. return [
  93. el?.textContent,
  94. el?.value,
  95. el?.getAttribute?.('aria-label'),
  96. el?.getAttribute?.('title'),
  97. ]
  98. .filter(Boolean)
  99. .join(' ')
  100. .replace(/\s+/g, ' ')
  101. .trim();
  102. }
  103. function isActionEnabled(el) {
  104. return Boolean(el)
  105. && !el.disabled
  106. && el.getAttribute('aria-disabled') !== 'true';
  107. }
  108. function findOneTimeCodeLoginTrigger() {
  109. const candidates = document.querySelectorAll(
  110. 'button, a, [role="button"], [role="link"], input[type="button"], input[type="submit"]'
  111. );
  112. for (const el of candidates) {
  113. if (!isVisibleElement(el)) continue;
  114. if (el.disabled || el.getAttribute('aria-disabled') === 'true') continue;
  115. const text = [
  116. el.textContent,
  117. el.value,
  118. el.getAttribute('aria-label'),
  119. el.getAttribute('title'),
  120. ]
  121. .filter(Boolean)
  122. .join(' ')
  123. .replace(/\s+/g, ' ')
  124. .trim();
  125. if (text && ONE_TIME_CODE_LOGIN_PATTERN.test(text)) {
  126. return el;
  127. }
  128. }
  129. return null;
  130. }
  131. function findResendVerificationCodeTrigger({ allowDisabled = false } = {}) {
  132. const candidates = document.querySelectorAll(
  133. 'button, a, [role="button"], [role="link"], input[type="button"], input[type="submit"]'
  134. );
  135. for (const el of candidates) {
  136. if (!isVisibleElement(el)) continue;
  137. if (!allowDisabled && !isActionEnabled(el)) continue;
  138. const text = getActionText(el);
  139. if (text && RESEND_VERIFICATION_CODE_PATTERN.test(text)) {
  140. return el;
  141. }
  142. }
  143. return null;
  144. }
  145. function isEmailVerificationPage() {
  146. return /\/email-verification(?:[/?#]|$)/i.test(location.pathname || '');
  147. }
  148. async function prepareLoginCodeFlow(timeout = 15000) {
  149. const readyTarget = getVerificationCodeTarget();
  150. if (readyTarget) {
  151. log('步骤 7:验证码输入框已就绪。');
  152. return { ready: true, mode: readyTarget.type };
  153. }
  154. if (isEmailVerificationPage() && isVerificationPageStillVisible()) {
  155. log('步骤 7:已进入邮箱验证码页面,正在等待验证码输入框或重发入口稳定。');
  156. return { ready: true, mode: 'verification_page' };
  157. }
  158. const start = Date.now();
  159. let switchClickCount = 0;
  160. let lastSwitchAttemptAt = 0;
  161. let loggedPasswordPage = false;
  162. let loggedVerificationPage = false;
  163. while (Date.now() - start < timeout) {
  164. throwIfStopped();
  165. const target = getVerificationCodeTarget();
  166. if (target) {
  167. log('步骤 7:验证码页面已就绪。');
  168. return { ready: true, mode: target.type };
  169. }
  170. if (isEmailVerificationPage() && isVerificationPageStillVisible()) {
  171. if (!loggedVerificationPage) {
  172. loggedVerificationPage = true;
  173. log('步骤 7:页面已进入邮箱验证码流程,继续等待验证码输入框渲染...');
  174. }
  175. await sleep(250);
  176. continue;
  177. }
  178. const passwordInput = document.querySelector('input[type="password"]');
  179. const switchTrigger = findOneTimeCodeLoginTrigger();
  180. if (switchTrigger && (switchClickCount === 0 || Date.now() - lastSwitchAttemptAt > 1500)) {
  181. switchClickCount += 1;
  182. lastSwitchAttemptAt = Date.now();
  183. loggedPasswordPage = false;
  184. log('步骤 7:检测到密码页,正在切换到一次性验证码登录...');
  185. await humanPause(350, 900);
  186. simulateClick(switchTrigger);
  187. await sleep(1200);
  188. continue;
  189. }
  190. if (passwordInput && !loggedPasswordPage) {
  191. loggedPasswordPage = true;
  192. log('步骤 7:正在等待密码页上的一次性验证码登录入口...');
  193. }
  194. await sleep(200);
  195. }
  196. throw new Error('无法切换到一次性验证码验证页面。URL: ' + location.href);
  197. }
  198. async function resendVerificationCode(step, timeout = 45000) {
  199. if (step === 7) {
  200. await prepareLoginCodeFlow();
  201. }
  202. const start = Date.now();
  203. let action = null;
  204. let loggedWaiting = false;
  205. while (Date.now() - start < timeout) {
  206. throwIfStopped();
  207. action = findResendVerificationCodeTrigger({ allowDisabled: true });
  208. if (action && isActionEnabled(action)) {
  209. log(`步骤 ${step}:重新发送验证码按钮已可用。`);
  210. await humanPause(350, 900);
  211. simulateClick(action);
  212. await sleep(1200);
  213. return {
  214. resent: true,
  215. buttonText: getActionText(action),
  216. };
  217. }
  218. if (action && !loggedWaiting) {
  219. loggedWaiting = true;
  220. log(`步骤 ${step}:正在等待重新发送验证码按钮变为可点击...`);
  221. }
  222. await sleep(250);
  223. }
  224. throw new Error('无法点击重新发送验证码按钮。URL: ' + location.href);
  225. }
  226. // ============================================================
  227. // Step 2: Click Register
  228. // ============================================================
  229. async function step2_clickRegister() {
  230. log('步骤 2:正在查找注册按钮...');
  231. let registerBtn = null;
  232. try {
  233. registerBtn = await waitForElementByText(
  234. 'a, button, [role="button"], [role="link"]',
  235. /sign\s*up|register|create\s*account|注册/i,
  236. 10000
  237. );
  238. } catch {
  239. // Some pages may have a direct link
  240. try {
  241. registerBtn = await waitForElement('a[href*="signup"], a[href*="register"]', 5000);
  242. } catch {
  243. throw new Error(
  244. '未找到注册按钮。' +
  245. '请在 DevTools 中检查认证页面 DOM。URL: ' + location.href
  246. );
  247. }
  248. }
  249. await humanPause(450, 1200);
  250. reportComplete(2);
  251. simulateClick(registerBtn);
  252. log('步骤 2:已点击注册按钮');
  253. }
  254. // ============================================================
  255. // Step 3: Fill Email & Password
  256. // ============================================================
  257. async function step3_fillEmailPassword(payload) {
  258. const { email } = payload;
  259. if (!email) throw new Error('未提供邮箱地址,请先在侧边栏粘贴邮箱。');
  260. log(`步骤 3:正在填写邮箱:${email}`);
  261. // Find email input
  262. let emailInput = null;
  263. try {
  264. emailInput = await waitForElement(
  265. 'input[type="email"], input[name="email"], input[name="username"], input[id*="email"], input[placeholder*="email"], input[placeholder*="Email"]',
  266. 10000
  267. );
  268. } catch {
  269. throw new Error('在注册页未找到邮箱输入框。URL: ' + location.href);
  270. }
  271. await humanPause(500, 1400);
  272. fillInput(emailInput, email);
  273. log('步骤 3:邮箱已填写');
  274. // Check if password field is on the same page
  275. let passwordInput = document.querySelector('input[type="password"]');
  276. if (!passwordInput) {
  277. // Need to submit email first to get to password page
  278. log('步骤 3:暂未发现密码输入框,先提交邮箱...');
  279. const submitBtn = document.querySelector('button[type="submit"]')
  280. || await waitForElementByText('button', /continue|next|submit|继续|下一步/i, 5000).catch(() => null);
  281. if (submitBtn) {
  282. await humanPause(400, 1100);
  283. simulateClick(submitBtn);
  284. log('步骤 3:邮箱已提交,正在等待密码输入框...');
  285. await sleep(2000);
  286. }
  287. try {
  288. passwordInput = await waitForElement('input[type="password"]', 10000);
  289. } catch {
  290. throw new Error('提交邮箱后仍未找到密码输入框。URL: ' + location.href);
  291. }
  292. }
  293. if (!payload.password) throw new Error('未提供密码,步骤 3 需要可用密码。');
  294. await humanPause(600, 1500);
  295. fillInput(passwordInput, payload.password);
  296. log('步骤 3:密码已填写');
  297. // Report complete BEFORE submit, because submit causes page navigation
  298. // which kills the content script connection
  299. reportComplete(3, { email });
  300. // Submit the form (page will navigate away after this)
  301. await sleep(500);
  302. const submitBtn = document.querySelector('button[type="submit"]')
  303. || await waitForElementByText('button', /continue|sign\s*up|submit|注册|创建|create/i, 5000).catch(() => null);
  304. if (submitBtn) {
  305. await humanPause(500, 1300);
  306. simulateClick(submitBtn);
  307. log('步骤 3:表单已提交');
  308. }
  309. }
  310. // ============================================================
  311. // Fill Verification Code (used by step 4 and step 7)
  312. // ============================================================
  313. const INVALID_VERIFICATION_CODE_PATTERN = /代码不正确|验证码不正确|验证码错误|code\s+(?:is\s+)?incorrect|invalid\s+code|incorrect\s+code|try\s+again/i;
  314. const VERIFICATION_PAGE_PATTERN = /检查您的收件箱|输入我们刚刚向|重新发送电子邮件|重新发送验证码|验证码|代码不正确|email\s+verification/i;
  315. const OAUTH_CONSENT_PAGE_PATTERN = /使用\s*ChatGPT\s*登录到\s*Codex|login\s+to\s+codex|log\s+in\s+to\s+codex|authorize|授权/i;
  316. const ADD_PHONE_PAGE_PATTERN = /add[\s-]*phone|添加手机号|手机号码|手机号|phone\s+number|telephone/i;
  317. const STEP5_SUBMIT_ERROR_PATTERN = /无法根据该信息创建帐户|请重试|unable\s+to\s+create\s+(?:your\s+)?account|couldn'?t\s+create\s+(?:your\s+)?account|something\s+went\s+wrong|invalid\s+(?:birthday|birth|date)|生日|出生日期/i;
  318. const SIGNUP_PASSWORD_ERROR_TITLE_PATTERN = /糟糕,出错了|something\s+went\s+wrong|oops/i;
  319. const SIGNUP_PASSWORD_ERROR_DETAIL_PATTERN = /operation\s+timed\s+out|timed\s+out|请求超时|操作超时/i;
  320. const SIGNUP_EMAIL_EXISTS_PATTERN = /与此电子邮件地址相关联的帐户已存在|account\s+associated\s+with\s+this\s+email\s+address\s+already\s+exists|email\s+address.*already\s+exists/i;
  321. function getVerificationErrorText() {
  322. const messages = [];
  323. const selectors = [
  324. '.react-aria-FieldError',
  325. '[slot="errorMessage"]',
  326. '[id$="-error"]',
  327. '[data-invalid="true"] + *',
  328. '[aria-invalid="true"] + *',
  329. '[class*="error"]',
  330. ];
  331. for (const selector of selectors) {
  332. document.querySelectorAll(selector).forEach((el) => {
  333. const text = (el.textContent || '').replace(/\s+/g, ' ').trim();
  334. if (text) {
  335. messages.push(text);
  336. }
  337. });
  338. }
  339. const invalidInput = document.querySelector(`${VERIFICATION_CODE_INPUT_SELECTOR}[aria-invalid="true"], ${VERIFICATION_CODE_INPUT_SELECTOR}[data-invalid="true"]`);
  340. if (invalidInput) {
  341. const wrapper = invalidInput.closest('form, [data-rac], ._root_18qcl_51, div');
  342. if (wrapper) {
  343. const text = (wrapper.textContent || '').replace(/\s+/g, ' ').trim();
  344. if (text) {
  345. messages.push(text);
  346. }
  347. }
  348. }
  349. return messages.find((text) => INVALID_VERIFICATION_CODE_PATTERN.test(text)) || '';
  350. }
  351. function isStep5Ready() {
  352. return Boolean(
  353. document.querySelector('input[name="name"], input[autocomplete="name"], input[name="birthday"], input[name="age"], [role="spinbutton"][data-type="year"]')
  354. );
  355. }
  356. function getPageTextSnapshot() {
  357. return (document.body?.innerText || document.body?.textContent || '')
  358. .replace(/\s+/g, ' ')
  359. .trim();
  360. }
  361. function getPrimaryContinueButton() {
  362. const continueBtn = document.querySelector(
  363. 'button[type="submit"][data-dd-action-name="Continue"], button[type="submit"]._primary_3rdp0_107'
  364. );
  365. if (continueBtn && isVisibleElement(continueBtn)) {
  366. return continueBtn;
  367. }
  368. const buttons = document.querySelectorAll('button, [role="button"]');
  369. return Array.from(buttons).find((el) => isVisibleElement(el) && /继续|Continue/i.test(el.textContent || '')) || null;
  370. }
  371. function isVerificationPageStillVisible() {
  372. if (getVerificationCodeTarget()) return true;
  373. if (findResendVerificationCodeTrigger({ allowDisabled: true })) return true;
  374. if (document.querySelector('form[action*="email-verification" i]')) return true;
  375. return VERIFICATION_PAGE_PATTERN.test(getPageTextSnapshot());
  376. }
  377. function isAddPhonePageReady() {
  378. const path = `${location.pathname || ''} ${location.href || ''}`;
  379. if (/\/add-phone(?:[/?#]|$)/i.test(path)) return true;
  380. const phoneInput = document.querySelector(
  381. 'input[type="tel"]:not([maxlength="6"]), input[name*="phone" i], input[id*="phone" i], input[autocomplete="tel"]'
  382. );
  383. if (phoneInput && isVisibleElement(phoneInput)) {
  384. return true;
  385. }
  386. return ADD_PHONE_PAGE_PATTERN.test(getPageTextSnapshot());
  387. }
  388. function isStep8Ready() {
  389. const continueBtn = getPrimaryContinueButton();
  390. if (!continueBtn) return false;
  391. if (isVerificationPageStillVisible()) return false;
  392. if (isAddPhonePageReady()) return false;
  393. return OAUTH_CONSENT_PAGE_PATTERN.test(getPageTextSnapshot());
  394. }
  395. function normalizeInlineText(text) {
  396. return (text || '').replace(/\s+/g, ' ').trim();
  397. }
  398. function findBirthdayReactAriaSelect(labelText) {
  399. const normalizedLabel = normalizeInlineText(labelText);
  400. const roots = document.querySelectorAll('.react-aria-Select');
  401. for (const root of roots) {
  402. const labelEl = Array.from(root.querySelectorAll('span')).find((el) => normalizeInlineText(el.textContent) === normalizedLabel);
  403. if (!labelEl) continue;
  404. const item = root.closest('[class*="selectItem"], ._selectItem_ppsls_113') || root.parentElement;
  405. const nativeSelect = item?.querySelector('[data-testid="hidden-select-container"] select') || null;
  406. const button = root.querySelector('button[aria-haspopup="listbox"]') || null;
  407. const valueEl = root.querySelector('.react-aria-SelectValue') || null;
  408. return { root, item, labelEl, nativeSelect, button, valueEl };
  409. }
  410. return null;
  411. }
  412. async function setReactAriaBirthdaySelect(control, value) {
  413. if (!control?.nativeSelect) {
  414. throw new Error('未找到可写入的生日下拉框。');
  415. }
  416. const desiredValue = String(value);
  417. const option = Array.from(control.nativeSelect.options).find((item) => item.value === desiredValue);
  418. if (!option) {
  419. throw new Error(`生日下拉框中不存在值 ${desiredValue}。`);
  420. }
  421. control.nativeSelect.value = desiredValue;
  422. option.selected = true;
  423. control.nativeSelect.dispatchEvent(new Event('input', { bubbles: true }));
  424. control.nativeSelect.dispatchEvent(new Event('change', { bubbles: true }));
  425. await sleep(120);
  426. }
  427. function getStep5ErrorText() {
  428. const messages = [];
  429. const selectors = [
  430. '.react-aria-FieldError',
  431. '[slot="errorMessage"]',
  432. '[id$="-error"]',
  433. '[id$="-errors"]',
  434. '[role="alert"]',
  435. '[aria-live="assertive"]',
  436. '[aria-live="polite"]',
  437. '[class*="error"]',
  438. ];
  439. for (const selector of selectors) {
  440. document.querySelectorAll(selector).forEach((el) => {
  441. if (!isVisibleElement(el)) return;
  442. const text = normalizeInlineText(el.textContent);
  443. if (text) {
  444. messages.push(text);
  445. }
  446. });
  447. }
  448. const invalidField = Array.from(document.querySelectorAll('[aria-invalid="true"], [data-invalid="true"]'))
  449. .find((el) => isVisibleElement(el));
  450. if (invalidField) {
  451. const wrapper = invalidField.closest('form, fieldset, [data-rac], div');
  452. if (wrapper) {
  453. const text = normalizeInlineText(wrapper.textContent);
  454. if (text) {
  455. messages.push(text);
  456. }
  457. }
  458. }
  459. return messages.find((text) => STEP5_SUBMIT_ERROR_PATTERN.test(text)) || '';
  460. }
  461. async function waitForStep5SubmitOutcome(timeout = 15000) {
  462. const start = Date.now();
  463. while (Date.now() - start < timeout) {
  464. throwIfStopped();
  465. const errorText = getStep5ErrorText();
  466. if (errorText) {
  467. return { invalidProfile: true, errorText };
  468. }
  469. if (isAddPhonePageReady()) {
  470. return { success: true, addPhonePage: true };
  471. }
  472. if (isStep8Ready()) {
  473. return { success: true };
  474. }
  475. await sleep(150);
  476. }
  477. const errorText = getStep5ErrorText();
  478. if (errorText) {
  479. return { invalidProfile: true, errorText };
  480. }
  481. return {
  482. invalidProfile: true,
  483. errorText: '提交后未进入下一阶段,请检查生日是否真正被页面接受。',
  484. };
  485. }
  486. function isSignupPasswordPage() {
  487. return /\/create-account\/password(?:[/?#]|$)/i.test(location.pathname || '');
  488. }
  489. function getSignupPasswordInput() {
  490. const input = document.querySelector('input[type="password"]');
  491. return input && isVisibleElement(input) ? input : null;
  492. }
  493. function getSignupPasswordSubmitButton({ allowDisabled = false } = {}) {
  494. const direct = document.querySelector('button[type="submit"]');
  495. if (direct && isVisibleElement(direct) && (allowDisabled || isActionEnabled(direct))) {
  496. return direct;
  497. }
  498. const candidates = document.querySelectorAll('button, [role="button"]');
  499. return Array.from(candidates).find((el) => {
  500. if (!isVisibleElement(el) || (!allowDisabled && !isActionEnabled(el))) return false;
  501. const text = getActionText(el);
  502. return /继续|continue|submit|创建|create/i.test(text);
  503. }) || null;
  504. }
  505. function getSignupRetryButton() {
  506. const direct = document.querySelector('button[data-dd-action-name="Try again"]');
  507. if (direct && isVisibleElement(direct) && isActionEnabled(direct)) {
  508. return direct;
  509. }
  510. const candidates = document.querySelectorAll('button, [role="button"]');
  511. return Array.from(candidates).find((el) => {
  512. if (!isVisibleElement(el) || !isActionEnabled(el)) return false;
  513. const text = getActionText(el);
  514. return /重试|try\s+again/i.test(text);
  515. }) || null;
  516. }
  517. function isSignupPasswordErrorPage() {
  518. if (!isSignupPasswordPage()) return false;
  519. const text = getPageTextSnapshot();
  520. return Boolean(
  521. getSignupRetryButton()
  522. && (SIGNUP_PASSWORD_ERROR_TITLE_PATTERN.test(text)
  523. || SIGNUP_PASSWORD_ERROR_DETAIL_PATTERN.test(text)
  524. || SIGNUP_PASSWORD_ERROR_TITLE_PATTERN.test(document.title || ''))
  525. );
  526. }
  527. function isSignupEmailAlreadyExistsPage() {
  528. return isSignupPasswordPage() && SIGNUP_EMAIL_EXISTS_PATTERN.test(getPageTextSnapshot());
  529. }
  530. function inspectSignupVerificationState() {
  531. if (isStep5Ready()) {
  532. return { state: 'step5' };
  533. }
  534. if (isVerificationPageStillVisible()) {
  535. return { state: 'verification' };
  536. }
  537. if (isSignupPasswordErrorPage()) {
  538. return {
  539. state: 'error',
  540. retryButton: getSignupRetryButton(),
  541. };
  542. }
  543. if (isSignupEmailAlreadyExistsPage()) {
  544. return { state: 'email_exists' };
  545. }
  546. const passwordInput = getSignupPasswordInput();
  547. if (passwordInput) {
  548. return {
  549. state: 'password',
  550. passwordInput,
  551. submitButton: getSignupPasswordSubmitButton({ allowDisabled: true }),
  552. };
  553. }
  554. return { state: 'unknown' };
  555. }
  556. async function waitForSignupVerificationTransition(timeout = 5000) {
  557. const start = Date.now();
  558. while (Date.now() - start < timeout) {
  559. throwIfStopped();
  560. const snapshot = inspectSignupVerificationState();
  561. if (snapshot.state === 'step5' || snapshot.state === 'verification' || snapshot.state === 'error' || snapshot.state === 'email_exists') {
  562. return snapshot;
  563. }
  564. await sleep(200);
  565. }
  566. return inspectSignupVerificationState();
  567. }
  568. async function prepareSignupVerificationFlow(payload = {}, timeout = 30000) {
  569. const { password } = payload;
  570. const start = Date.now();
  571. let recoveryRound = 0;
  572. const maxRecoveryRounds = 3;
  573. while (Date.now() - start < timeout && recoveryRound < maxRecoveryRounds) {
  574. throwIfStopped();
  575. const roundNo = recoveryRound + 1;
  576. log(`步骤 4:等待页面进入验证码阶段(第 ${roundNo}/${maxRecoveryRounds} 轮,先等待 5 秒)...`, 'info');
  577. const snapshot = await waitForSignupVerificationTransition(5000);
  578. if (snapshot.state === 'step5') {
  579. log('步骤 4:页面已进入验证码后的下一阶段,本步骤按已完成处理。', 'ok');
  580. return { ready: true, alreadyVerified: true, retried: recoveryRound };
  581. }
  582. if (snapshot.state === 'verification') {
  583. log(`步骤 4:验证码页面已就绪${recoveryRound ? `(期间自动恢复 ${recoveryRound} 次)` : ''}。`, 'ok');
  584. return { ready: true, retried: recoveryRound };
  585. }
  586. if (snapshot.state === 'email_exists') {
  587. throw new Error('当前邮箱已存在,需要重新开始新一轮。');
  588. }
  589. recoveryRound += 1;
  590. if (snapshot.state === 'error') {
  591. if (snapshot.retryButton && isActionEnabled(snapshot.retryButton)) {
  592. log(`步骤 4:检测到密码页超时报错,正在点击“重试”(第 ${recoveryRound}/${maxRecoveryRounds} 次)...`, 'warn');
  593. await humanPause(350, 900);
  594. simulateClick(snapshot.retryButton);
  595. await sleep(1200);
  596. continue;
  597. }
  598. log(`步骤 4:检测到异常页,但“重试”按钮暂不可用,准备继续等待(${recoveryRound}/${maxRecoveryRounds})...`, 'warn');
  599. continue;
  600. }
  601. if (snapshot.state === 'password') {
  602. if (!password) {
  603. throw new Error('当前回到了密码页,但没有可用密码,无法自动重新提交。');
  604. }
  605. if ((snapshot.passwordInput.value || '') !== password) {
  606. log('步骤 4:页面仍停留在密码页,正在重新填写密码...', 'warn');
  607. await humanPause(450, 1100);
  608. fillInput(snapshot.passwordInput, password);
  609. }
  610. if (snapshot.submitButton && isActionEnabled(snapshot.submitButton)) {
  611. log(`步骤 4:页面仍停留在密码页,正在重新点击“继续”(第 ${recoveryRound}/${maxRecoveryRounds} 次)...`, 'warn');
  612. await humanPause(350, 900);
  613. simulateClick(snapshot.submitButton);
  614. await sleep(1200);
  615. continue;
  616. }
  617. log(`步骤 4:页面仍停留在密码页,但“继续”按钮暂不可用,准备继续等待(${recoveryRound}/${maxRecoveryRounds})...`, 'warn');
  618. continue;
  619. }
  620. log(`步骤 4:页面仍在切换中,准备继续等待(${recoveryRound}/${maxRecoveryRounds})...`, 'warn');
  621. }
  622. throw new Error(`等待注册验证码页面就绪超时或自动恢复失败(已尝试 ${recoveryRound}/${maxRecoveryRounds} 轮)。URL: ${location.href}`);
  623. }
  624. async function waitForVerificationSubmitOutcome(step, timeout) {
  625. const resolvedTimeout = timeout ?? (step === 7 ? 30000 : 12000);
  626. const start = Date.now();
  627. while (Date.now() - start < resolvedTimeout) {
  628. throwIfStopped();
  629. const errorText = getVerificationErrorText();
  630. if (errorText) {
  631. return { invalidCode: true, errorText };
  632. }
  633. if (step === 4 && isStep5Ready()) {
  634. return { success: true };
  635. }
  636. if (step === 7 && isStep8Ready()) {
  637. return { success: true };
  638. }
  639. if (step === 7 && isAddPhonePageReady()) {
  640. return { success: true, addPhonePage: true };
  641. }
  642. await sleep(150);
  643. }
  644. if (isVerificationPageStillVisible()) {
  645. return {
  646. invalidCode: true,
  647. errorText: getVerificationErrorText() || '提交后仍停留在验证码页面,准备重新发送验证码。',
  648. };
  649. }
  650. return { success: true, assumed: true };
  651. }
  652. async function fillVerificationCode(step, payload) {
  653. const { code } = payload;
  654. if (!code) throw new Error('未提供验证码。');
  655. log(`步骤 ${step}:正在填写验证码:${code}`);
  656. if (step === 7) {
  657. await prepareLoginCodeFlow();
  658. }
  659. // Find code input — could be a single input or multiple separate inputs
  660. let codeInput = null;
  661. try {
  662. codeInput = await waitForElement(VERIFICATION_CODE_INPUT_SELECTOR, 10000);
  663. } catch {
  664. // Check for multiple single-digit inputs (common pattern)
  665. const singleInputs = document.querySelectorAll('input[maxlength="1"]');
  666. if (singleInputs.length >= 6) {
  667. log(`步骤 ${step}:发现分开的单字符验证码输入框,正在逐个填写...`);
  668. for (let i = 0; i < 6 && i < singleInputs.length; i++) {
  669. fillInput(singleInputs[i], code[i]);
  670. await sleep(100);
  671. }
  672. const outcome = await waitForVerificationSubmitOutcome(step);
  673. if (outcome.invalidCode) {
  674. log(`步骤 ${step}:验证码被拒绝:${outcome.errorText}`, 'warn');
  675. } else if (outcome.addPhonePage) {
  676. log(`步骤 ${step}:验证码已通过,并已跳转到手机号页面。`, 'ok');
  677. } else {
  678. log(`步骤 ${step}:验证码已通过${outcome.assumed ? '(按成功推定)' : ''}。`, 'ok');
  679. }
  680. return outcome;
  681. }
  682. throw new Error('未找到验证码输入框。URL: ' + location.href);
  683. }
  684. fillInput(codeInput, code);
  685. log(`步骤 ${step}:验证码已填写`);
  686. // Report complete BEFORE submit (page may navigate away)
  687. // Submit
  688. await sleep(500);
  689. const submitBtn = document.querySelector('button[type="submit"]')
  690. || await waitForElementByText('button', /verify|confirm|submit|continue|确认|验证/i, 5000).catch(() => null);
  691. if (submitBtn) {
  692. await humanPause(450, 1200);
  693. simulateClick(submitBtn);
  694. log(`步骤 ${step}:验证码已提交`);
  695. }
  696. const outcome = await waitForVerificationSubmitOutcome(step);
  697. if (outcome.invalidCode) {
  698. log(`步骤 ${step}:验证码被拒绝:${outcome.errorText}`, 'warn');
  699. } else if (outcome.addPhonePage) {
  700. log(`步骤 ${step}:验证码已通过,并已跳转到手机号页面。`, 'ok');
  701. } else {
  702. log(`步骤 ${step}:验证码已通过${outcome.assumed ? '(按成功推定)' : ''}。`, 'ok');
  703. }
  704. return outcome;
  705. }
  706. // ============================================================
  707. // Step 6: Login with registered account (on OAuth auth page)
  708. // ============================================================
  709. async function step6_login(payload) {
  710. const { email, password } = payload;
  711. if (!email) throw new Error('登录时缺少邮箱地址。');
  712. log(`步骤 6:正在使用 ${email} 登录...`);
  713. // Wait for email input on the auth page
  714. let emailInput = null;
  715. try {
  716. emailInput = await waitForElement(
  717. 'input[type="email"], input[name="email"], input[name="username"], input[id*="email"], input[placeholder*="email" i], input[placeholder*="Email"]',
  718. 15000
  719. );
  720. } catch {
  721. throw new Error('在登录页未找到邮箱输入框。URL: ' + location.href);
  722. }
  723. await humanPause(500, 1400);
  724. fillInput(emailInput, email);
  725. log('步骤 6:邮箱已填写');
  726. // Submit email
  727. await sleep(500);
  728. const submitBtn1 = document.querySelector('button[type="submit"]')
  729. || await waitForElementByText('button', /continue|next|submit|继续|下一步/i, 5000).catch(() => null);
  730. if (submitBtn1) {
  731. await humanPause(400, 1100);
  732. simulateClick(submitBtn1);
  733. log('步骤 6:邮箱已提交');
  734. }
  735. await sleep(2000);
  736. // Check for password field
  737. const passwordInput = document.querySelector('input[type="password"]');
  738. if (passwordInput) {
  739. log('步骤 6:已找到密码输入框,正在填写密码...');
  740. await humanPause(550, 1450);
  741. fillInput(passwordInput, password);
  742. await sleep(500);
  743. const submitBtn2 = document.querySelector('button[type="submit"]')
  744. || await waitForElementByText('button', /continue|log\s*in|submit|sign\s*in|登录|继续/i, 5000).catch(() => null);
  745. // Report complete BEFORE submit in case page navigates
  746. reportComplete(6, { needsOTP: true });
  747. if (submitBtn2) {
  748. await humanPause(450, 1200);
  749. simulateClick(submitBtn2);
  750. log('步骤 6:密码已提交,可能还需要验证码(步骤 7)');
  751. }
  752. return;
  753. }
  754. // No password field — OTP flow
  755. log('步骤 6:未发现密码输入框,可能进入验证码流程或自动跳转。');
  756. reportComplete(6, { needsOTP: true });
  757. }
  758. // ============================================================
  759. // Step 8: Find "继续" on OAuth consent page for debugger click
  760. // ============================================================
  761. // After login + verification, page shows:
  762. // "使用 ChatGPT 登录到 Codex" with a "继续" submit button.
  763. // Background performs the actual click through the debugger Input API.
  764. async function step8_findAndClick() {
  765. log('步骤 8:正在查找 OAuth 同意页的“继续”按钮...');
  766. const continueBtn = await findContinueButton();
  767. await waitForButtonEnabled(continueBtn);
  768. await humanPause(350, 900);
  769. continueBtn.scrollIntoView({ behavior: 'smooth', block: 'center' });
  770. continueBtn.focus();
  771. await sleep(250);
  772. const rect = getSerializableRect(continueBtn);
  773. log('步骤 8:已找到“继续”按钮并准备好调试器点击坐标。');
  774. return {
  775. rect,
  776. buttonText: (continueBtn.textContent || '').trim(),
  777. url: location.href,
  778. };
  779. }
  780. async function findContinueButton() {
  781. const start = Date.now();
  782. while (Date.now() - start < 10000) {
  783. throwIfStopped();
  784. if (isAddPhonePageReady()) {
  785. throw new Error('当前页面已进入手机号页面,不是 OAuth 授权同意页。URL: ' + location.href);
  786. }
  787. const button = getPrimaryContinueButton();
  788. if (button && isStep8Ready()) {
  789. return button;
  790. }
  791. await sleep(150);
  792. }
  793. throw new Error('在 OAuth 同意页未找到“继续”按钮,或页面尚未进入授权同意状态。URL: ' + location.href);
  794. }
  795. async function waitForButtonEnabled(button, timeout = 8000) {
  796. const start = Date.now();
  797. while (Date.now() - start < timeout) {
  798. throwIfStopped();
  799. if (isButtonEnabled(button)) return;
  800. await sleep(150);
  801. }
  802. throw new Error('“继续”按钮长时间不可点击。URL: ' + location.href);
  803. }
  804. function isButtonEnabled(button) {
  805. return Boolean(button)
  806. && !button.disabled
  807. && button.getAttribute('aria-disabled') !== 'true';
  808. }
  809. function getSerializableRect(el) {
  810. const rect = el.getBoundingClientRect();
  811. if (!rect.width || !rect.height) {
  812. throw new Error('滚动后“继续”按钮没有可点击尺寸。URL: ' + location.href);
  813. }
  814. return {
  815. left: rect.left,
  816. top: rect.top,
  817. width: rect.width,
  818. height: rect.height,
  819. centerX: rect.left + (rect.width / 2),
  820. centerY: rect.top + (rect.height / 2),
  821. };
  822. }
  823. // ============================================================
  824. // Step 5: Fill Name & Birthday / Age
  825. // ============================================================
  826. async function step5_fillNameBirthday(payload) {
  827. const { firstName, lastName, age, year, month, day } = payload;
  828. if (!firstName || !lastName) throw new Error('未提供姓名数据。');
  829. const resolvedAge = age ?? (year ? new Date().getFullYear() - Number(year) : null);
  830. const hasBirthdayData = [year, month, day].every(value => value != null && !Number.isNaN(Number(value)));
  831. if (!hasBirthdayData && (resolvedAge == null || Number.isNaN(Number(resolvedAge)))) {
  832. throw new Error('未提供生日或年龄数据。');
  833. }
  834. const fullName = `${firstName} ${lastName}`;
  835. log(`步骤 5:正在填写姓名:${fullName}`);
  836. // Actual DOM structure:
  837. // - Full name: <input name="name" placeholder="全名" type="text">
  838. // - Birthday: React Aria DateField or hidden input[name="birthday"]
  839. // - Age: <input name="age" type="text|number">
  840. // --- Full Name (single field, not first+last) ---
  841. let nameInput = null;
  842. try {
  843. nameInput = await waitForElement(
  844. 'input[name="name"], input[placeholder*="全名"], input[autocomplete="name"]',
  845. 10000
  846. );
  847. } catch {
  848. throw new Error('未找到姓名输入框。URL: ' + location.href);
  849. }
  850. await humanPause(500, 1300);
  851. fillInput(nameInput, fullName);
  852. log(`步骤 5:姓名已填写:${fullName}`);
  853. let birthdayMode = false;
  854. let ageInput = null;
  855. let yearSpinner = null;
  856. let monthSpinner = null;
  857. let daySpinner = null;
  858. let hiddenBirthday = null;
  859. let yearReactSelect = null;
  860. let monthReactSelect = null;
  861. let dayReactSelect = null;
  862. let visibleAgeInput = false;
  863. let visibleBirthdaySpinners = false;
  864. let visibleBirthdaySelects = false;
  865. for (let i = 0; i < 100; i++) {
  866. yearSpinner = document.querySelector('[role="spinbutton"][data-type="year"]');
  867. monthSpinner = document.querySelector('[role="spinbutton"][data-type="month"]');
  868. daySpinner = document.querySelector('[role="spinbutton"][data-type="day"]');
  869. hiddenBirthday = document.querySelector('input[name="birthday"]');
  870. ageInput = document.querySelector('input[name="age"]');
  871. yearReactSelect = findBirthdayReactAriaSelect('年');
  872. monthReactSelect = findBirthdayReactAriaSelect('月');
  873. dayReactSelect = findBirthdayReactAriaSelect('天');
  874. visibleAgeInput = Boolean(ageInput && isVisibleElement(ageInput));
  875. visibleBirthdaySpinners = Boolean(
  876. yearSpinner
  877. && monthSpinner
  878. && daySpinner
  879. && isVisibleElement(yearSpinner)
  880. && isVisibleElement(monthSpinner)
  881. && isVisibleElement(daySpinner)
  882. );
  883. visibleBirthdaySelects = Boolean(
  884. yearReactSelect?.button
  885. && monthReactSelect?.button
  886. && dayReactSelect?.button
  887. && isVisibleElement(yearReactSelect.button)
  888. && isVisibleElement(monthReactSelect.button)
  889. && isVisibleElement(dayReactSelect.button)
  890. );
  891. if (visibleAgeInput) break;
  892. if (visibleBirthdaySpinners || visibleBirthdaySelects) {
  893. birthdayMode = true;
  894. break;
  895. }
  896. await sleep(100);
  897. }
  898. if (birthdayMode) {
  899. if (!hasBirthdayData) {
  900. throw new Error('检测到生日字段,但未提供生日数据。');
  901. }
  902. const yearSpinner = document.querySelector('[role="spinbutton"][data-type="year"]');
  903. const monthSpinner = document.querySelector('[role="spinbutton"][data-type="month"]');
  904. const daySpinner = document.querySelector('[role="spinbutton"][data-type="day"]');
  905. const yearReactSelect = findBirthdayReactAriaSelect('年');
  906. const monthReactSelect = findBirthdayReactAriaSelect('月');
  907. const dayReactSelect = findBirthdayReactAriaSelect('天');
  908. if (yearReactSelect?.nativeSelect && monthReactSelect?.nativeSelect && dayReactSelect?.nativeSelect) {
  909. const desiredDate = `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
  910. const hiddenBirthday = document.querySelector('input[name="birthday"]');
  911. log('步骤 5:检测到 React Aria 下拉生日字段,正在填写生日...');
  912. await humanPause(450, 1100);
  913. await setReactAriaBirthdaySelect(yearReactSelect, year);
  914. await humanPause(250, 650);
  915. await setReactAriaBirthdaySelect(monthReactSelect, month);
  916. await humanPause(250, 650);
  917. await setReactAriaBirthdaySelect(dayReactSelect, day);
  918. if (hiddenBirthday) {
  919. const start = Date.now();
  920. while (Date.now() - start < 2000) {
  921. if ((hiddenBirthday.value || '') === desiredDate) break;
  922. await sleep(100);
  923. }
  924. if ((hiddenBirthday.value || '') !== desiredDate) {
  925. throw new Error(`生日值未成功写入页面。期望 ${desiredDate},实际 ${(hiddenBirthday.value || '空')}。`);
  926. }
  927. }
  928. log(`步骤 5:React Aria 生日已填写:${desiredDate}`);
  929. }
  930. if (yearSpinner && monthSpinner && daySpinner) {
  931. log('步骤 5:检测到生日字段,正在填写生日...');
  932. async function setSpinButton(el, value) {
  933. el.focus();
  934. await sleep(100);
  935. document.execCommand('selectAll', false, null);
  936. await sleep(50);
  937. const valueStr = String(value);
  938. for (const char of valueStr) {
  939. el.dispatchEvent(new KeyboardEvent('keydown', { key: char, code: `Digit${char}`, bubbles: true }));
  940. el.dispatchEvent(new KeyboardEvent('keypress', { key: char, code: `Digit${char}`, bubbles: true }));
  941. el.dispatchEvent(new InputEvent('beforeinput', { inputType: 'insertText', data: char, bubbles: true }));
  942. el.dispatchEvent(new InputEvent('input', { inputType: 'insertText', data: char, bubbles: true }));
  943. await sleep(50);
  944. }
  945. el.dispatchEvent(new KeyboardEvent('keyup', { key: 'Tab', code: 'Tab', bubbles: true }));
  946. el.blur();
  947. await sleep(100);
  948. }
  949. await humanPause(450, 1100);
  950. await setSpinButton(yearSpinner, year);
  951. await humanPause(250, 650);
  952. await setSpinButton(monthSpinner, String(month).padStart(2, '0'));
  953. await humanPause(250, 650);
  954. await setSpinButton(daySpinner, String(day).padStart(2, '0'));
  955. log(`步骤 5:生日已填写:${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`);
  956. }
  957. const hiddenBirthday = document.querySelector('input[name="birthday"]');
  958. if (hiddenBirthday) {
  959. const dateStr = `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
  960. hiddenBirthday.value = dateStr;
  961. hiddenBirthday.dispatchEvent(new Event('input', { bubbles: true }));
  962. hiddenBirthday.dispatchEvent(new Event('change', { bubbles: true }));
  963. log(`步骤 5:已设置隐藏生日输入框:${dateStr}`);
  964. }
  965. } else if (ageInput) {
  966. if (resolvedAge == null || Number.isNaN(Number(resolvedAge))) {
  967. throw new Error('检测到年龄字段,但未提供年龄数据。');
  968. }
  969. await humanPause(500, 1300);
  970. fillInput(ageInput, String(resolvedAge));
  971. log(`步骤 5:年龄已填写:${resolvedAge}`);
  972. } else {
  973. throw new Error('未找到生日或年龄输入项。URL: ' + location.href);
  974. }
  975. // Click "完成帐户创建" button
  976. await sleep(500);
  977. const completeBtn = document.querySelector('button[type="submit"]')
  978. || await waitForElementByText('button', /完成|create|continue|finish|done|agree/i, 5000).catch(() => null);
  979. if (!completeBtn) {
  980. throw new Error('未找到“完成帐户创建”按钮。URL: ' + location.href);
  981. }
  982. await humanPause(500, 1300);
  983. simulateClick(completeBtn);
  984. log('步骤 5:已点击“完成帐户创建”,正在等待页面结果...');
  985. const outcome = await waitForStep5SubmitOutcome();
  986. if (outcome.invalidProfile) {
  987. throw new Error(`步骤 5:${outcome.errorText}`);
  988. }
  989. log(`步骤 5:资料已通过。`, 'ok');
  990. reportComplete(5, { addPhonePage: Boolean(outcome.addPhonePage) });
  991. }