File size: 1,549 Bytes
3007a63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const { chromium } = require('playwright-core');
(async () => {
  const b = await chromium.launch({
    executablePath: '/data/tools/chrome-headless-shell-linux64/chrome-headless-shell',
    args: ['--no-sandbox','--disable-dev-shm-usage','--use-gl=swiftshader','--enable-unsafe-swiftshader'],
  });
  const ctx = await b.newContext({ viewport: { width: 1600, height: 1000 }, locale: 'zh-CN' });
  await ctx.addInitScript(() => { try { localStorage.setItem('sb_locale','zh-CN'); } catch(e){} });
  const page = await ctx.newPage();
  await page.goto('http://127.0.0.1/', { waitUntil: 'domcontentloaded', timeout: 60000 });
  await page.waitForTimeout(12000);
  // 走引导
  for (let i=0;i<25;i++){
    const c = await page.evaluate(() => {
      const norm = s => (s||'').trim().toUpperCase();
      const btns = [...document.querySelectorAll('button,[role="button"]')].filter(e=>e.offsetParent!==null);
      for (const w of ['启动','开始','继续','下一步','跳过','进入','LAUNCH','CONTINUE','NEXT','SKIP']) {
        const h = btns.find(x=>norm(x.innerText)===w.toUpperCase());
        if (h){h.click();return w;}
      }
      return null;
    });
    if(!c) break; await page.waitForTimeout(3000);
  }
  await page.waitForTimeout(40000);
  await page.screenshot({ path: '/data/shots/sb_zh.png' });
  const t = (await page.evaluate(()=>document.body.innerText)).replace(/\s+/g,' ');
  console.log('chinese_chars', (t.match(/[一-龥]/g)||[]).length, 'len', t.length);
  console.log('HEAD:', t.slice(0,300));
  await b.close();
})();