| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- // Instrumented read-only UI probe. Logs each step immediately so a hang is visible.
- const { chromium } = require('playwright-core');
- const fs = require('fs');
- const path = require('path');
- const CACHE = path.join(process.env.LOCALAPPDATA || 'C:/Users/iwt/AppData/Local', 'ms-playwright');
- function findChrome() {
- for (const rev of ['chromium-1234', 'chromium-1228']) {
- const exe = path.join(CACHE, rev, 'chrome-win64', 'chrome.exe');
- if (fs.existsSync(exe)) return exe;
- }
- return null;
- }
- const TARGET = process.env.PW_BASE_URL || 'http://cfc.iwintrue.com/frontend';
- const EXE = findChrome();
- const log = (...a) => { process.stdout.write('[' + new Date().toISOString().slice(11, 19) + '] ' + a.join(' ') + '\n'); };
- // Hard kill switch so we never hang the session.
- const KILL = setTimeout(() => { log('HARD_TIMEOUT 60s -> exiting'); process.exit(3); }, 60000);
- (async () => {
- log('chrome_exe=' + EXE);
- if (!EXE) { log('NO CHROME'); process.exit(2); }
- const browser = await chromium.launch({
- executablePath: EXE, headless: true,
- args: ['--no-sandbox', '--disable-dev-shm-usage', '--disable-gpu'],
- });
- log('launched');
- const page = await browser.newPage({ viewport: { width: 1280, height: 800 } });
- page.on('console', (m) => { if (m.type() === 'error') log('console.error: ' + m.text().slice(0, 120)); });
- page.on('pageerror', (e) => log('pageerror: ' + e.message.slice(0, 120)));
- page.on('requestfailed', (r) => log('requestfailed: ' + r.url().slice(0, 80) + ' ' + (r.failure() && r.failure().errorText)));
- log('goto ' + TARGET);
- const resp = await page.goto(TARGET, { waitUntil: 'domcontentloaded', timeout: 20000 });
- log('goto done status=' + (resp ? resp.status() : 'null') + ' url=' + page.url());
- const ua = await page.evaluate(() => navigator.userAgent);
- log('ua=' + ua);
- await page.waitForTimeout(2000).catch(() => {});
- const title = await page.title();
- const bodyLen = await page.evaluate(() => (document.body ? document.body.innerText.length : 0));
- log('title=' + JSON.stringify(title) + ' bodyTextLen=' + bodyLen);
- const mount = await page.evaluate(() => {
- const out = [];
- for (const id of ['app', 'root']) if (document.getElementById(id)) out.push(id);
- return out;
- });
- log('mountRoots=' + JSON.stringify(mount));
- const markers = await page.evaluate(() => {
- const txt = (document.body ? document.body.innerText : '').toLowerCase();
- const inputs = Array.from(document.querySelectorAll('input')).map((i) => i.type || 'text');
- return { inputTypes: [...new Set(inputs)], mentionsLogin: /登录|login|用户名|密码|password/i.test(txt) };
- });
- log('markers=' + JSON.stringify(markers));
- log('PROBE_OK');
- await browser.close();
- clearTimeout(KILL);
- process.exit(0);
- })().catch((e) => { log('ERR ' + (e && e.message ? e.message : e)); process.exit(1); });
|