helloworld / deploy /scripts /shot_sb_zh.js
eduzrh's picture
Upload deploy/scripts/shot_sb_zh.js with huggingface_hub
3007a63 verified
Raw History Blame Contribute Delete
1.55 kB
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();
})();