云
5 天以前 2c3df98c784bd825b6c2faab508e20fe4f2c3966
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/** 登录页结构诊断:把实际渲染出来的表单元素全部打出来 */
const { chromium } = require('playwright');
 
(async () => {
  const browser = await chromium.launch({ headless: true });
  const page = await browser.newPage({ viewport: { width: 1600, height: 900 } });
  const errors = [];
  page.on('pageerror', (e) => errors.push('pageerror: ' + e.message));
  page.on('console', (m) => {
    if (m.type() === 'error') errors.push('console: ' + m.text());
  });
  page.on('requestfailed', (r) =>
    errors.push('reqfail: ' + r.url() + ' ' + (r.failure() || {}).errorText),
  );
 
  await page.goto('http://127.0.0.1:5666/auth/login', { waitUntil: 'domcontentloaded' });
  await page.waitForTimeout(8000);
 
  console.log('URL:', page.url());
  console.log('TITLE:', await page.title());
  const bodyText = (await page.locator('body').innerText().catch(() => '')).slice(0, 800);
  console.log('--- 可见文本 ---');
  console.log(bodyText);
 
  console.log('--- input 元素 ---');
  for (const el of await page.locator('input').all()) {
    console.log(
      JSON.stringify({
        type: await el.getAttribute('type'),
        name: await el.getAttribute('name'),
        autocomplete: await el.getAttribute('autocomplete'),
        placeholder: await el.getAttribute('placeholder'),
        id: await el.getAttribute('id'),
        visible: await el.isVisible().catch(() => false),
      }),
    );
  }
 
  console.log('--- button/role=radio 元素 ---');
  for (const el of await page.locator('button, [role=radio], .ant-radio-wrapper').all()) {
    const t = (await el.innerText().catch(() => '')).trim().slice(0, 40);
    if (t) console.log(JSON.stringify({ tag: await el.evaluate((n) => n.tagName), text: t }));
  }
 
  console.log('--- 错误 ---');
  console.log(errors.slice(0, 20).join('\n') || '(无)');
  await page.screenshot({
    path: require('node:path').join(__dirname, 'qr-export-test-out', 'diag-login.png'),
  });
  await browser.close();
})();