Intelligence, Advanced Charting & Trading Platform

1 import { chromium } from 'playwright';
2
3 const candidates=[
4 {name:'candidate-version-27',url:'https://2cbeb4e2-velyqor-preview.davoodmehraban89.workers.dev/'},
5 {name:'current-production',url:'https://app.chartnova.ir/'}
6 ];
7 const browser=await chromium.launch({headless:true});
8 let failed=false;
9 const results=[];
10 try{
11 for(const target of candidates){
12 const ctx=await browser.newContext({viewport:{width:390,height:844},isMobile:true,hasTouch:true,serviceWorkers:'block'});
13 const page=await ctx.newPage();
14 const errors=[],badRequests=[];
15 page.on('pageerror',e=>errors.push(String(e.message).slice(0,280)));
16 page.on('requestfailed',r=>badRequests.push({path:new URL(r.url()).pathname,reason:r.failure()?.errorText}));
17 await page.addInitScript(()=>{
18 window.__chartnovaPaint={};
19 document.addEventListener('DOMContentLoaded',()=>{
20 for(const name of ['usd','gold18','xau','status']){
21 const el=document.getElementById(name);
22 if(!el)continue;
23 const observe=()=>{
24 const content=el.textContent||'';
25 const p=window.__chartnovaPaint;
26 if(name==='status'&&content.includes('قیمت‌های اصلی')&&!p.primaryStatusMs)p.primaryStatusMs=Math.round(performance.now());
27 if(name==='status'&&content.includes('داده بازار به‌روز')&&!p.completeMs)p.completeMs=Math.round(performance.now());
28 if(name==='usd'&&!content.includes('در حال دریافت')&&content.trim()&&!p.usdMs)p.usdMs=Math.round(performance.now());
29 if(name==='gold18'&&!content.includes('در حال دریافت')&&content.trim()&&!p.goldMs)p.goldMs=Math.round(performance.now());
30 if(name==='xau'&&!content.includes('در حال دریافت')&&content.trim()&&!p.xauMs)p.xauMs=Math.round(performance.now());
31 };
32 new MutationObserver(observe).observe(el,{characterData:true,childList:true,subtree:true});
33 observe();
34 }
35 },{once:true});
36 });
37 let stats={name:target.name};
38 try{
39 const res=await page.goto(target.url,{waitUntil:'domcontentloaded',timeout:18000});
40 stats.htmlStatus=res?.status();
41 await page.waitForFunction(()=>{
42 const m=document.getElementById('status')?.textContent||'';
43 return m.includes('به‌روز')||m.includes('غیرلحظه‌ای')||m.includes('در دسترس نیستند');
44 },{timeout:15000}).catch(()=>{});
45 await page.waitForTimeout(1000);
46 stats.ui=await page.evaluate(()=>({
47 title:document.title,visible:!!document.querySelector('.shell')?.getBoundingClientRect().width,
48 quoteUsd:document.getElementById('usd')?.textContent?.slice(0,80),
49 quoteGold:document.getElementById('gold18')?.textContent?.slice(0,80),
50 quoteXau:document.getElementById('xau')?.textContent?.slice(0,80),
51 status:document.getElementById('status')?.textContent?.slice(0,140),
52 markets:document.getElementById('marketCount')?.textContent?.slice(0,120),
53 marks:window.__chartnovaPaint
54 }));
55 await page.locator('[data-nav="markets"]').first().click();
56 stats.marketTab=await page.locator('#marketgrid .marketitem').count();
57 await page.locator('[data-nav="technical"]').first().click();
58 stats.technicalTab=await page.locator('#techTitle').textContent();
59 stats.errors=errors;stats.failedRequests=badRequests.slice(0,8);
60 if(stats.htmlStatus!==200||!stats.ui.visible||stats.marketTab<10||errors.length)failed=true;
61 }catch(e){failed=true;stats.error=String(e).slice(0,430);}
62 results.push(stats);await ctx.close();
63 }
64 }finally{await browser.close()}
65 console.log('CHARTNOVA_PRODUCTION_VS_STAGED_PERFORMANCE '+JSON.stringify(results));
66 if(failed)process.exitCode=1;