Intelligence, Advanced Charting & Trading Platform
test(diag): add read-only production browser and inline JS diagnostic
davoodmehraban89 committed
Oct 15, 2026 at 01:22 UTC
e614701bc575ca9e91bcc627a5ca23b51f24ddf3
1 file changed
+81
scripts/diagnose-chartnova-public.mjs
new
+81
@@ -0,0 +1,81 @@
1
+import { chromium } from 'playwright';
2
+import { Script } from 'node:vm';
3
+
4
+const HOST = 'https://app.chartnova.ir/';
5
+const TIMEOUT = 25_000;
6
+const report = { target: HOST, checkedAt: new Date().toISOString(), html: {}, sessions: [] };
7
+const safe = err => String(err?.message ?? err).slice(0, 400);
8
+let failed = false;
9
+
10
+// External GET only, no account sign-in, no credential collection, no cloud mutations.
11
+try {
12
+ const response = await fetch(HOST, { signal: AbortSignal.timeout(TIMEOUT), headers: { 'Cache-Control': 'no-cache' } });
13
+ const html = await response.text();
14
+ const match = [...html.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];
15
+ report.html = {
16
+ status: response.status, type: response.headers.get('content-type'),
17
+ bytes: html.length, inlineScripts: match.length,
18
+ hasVisibleAppMarkup: html.includes('class="shell"'),
19
+ cacheControl: response.headers.get('cache-control'),
20
+ };
21
+ for (const [i, item] of match.entries()) {
22
+ if (item[1].includes('src=')) continue;
23
+ try { new Script(item[2], { filename: 'production-inline-' + i + '.js' }); }
24
+ catch (err) { failed = true; report.html.syntaxError = safe(err); }
25
+ }
26
+ if (!response.ok || !report.html.hasVisibleAppMarkup) failed = true;
27
+} catch (e) { failed = true; report.html.networkError = safe(e); }
28
+
29
+const browser = await chromium.launch({ headless: true });
30
+try {
31
+ const suites = [
32
+ { name: 'desktop-sw-blocked', viewport: { width: 1366, height: 768 }, mobile: false, serviceWorkers: 'block' },
33
+ { name: 'mobile-sw-blocked', viewport: { width: 390, height: 844 }, mobile: true, serviceWorkers: 'block' },
34
+ { name: 'mobile-sw-allowed', viewport: { width: 390, height: 844 }, mobile: true, serviceWorkers: 'allow' }
35
+ ];
36
+ for (const spec of suites) {
37
+ const context = await browser.newContext({
38
+ viewport: spec.viewport, isMobile: spec.mobile, hasTouch: spec.mobile,
39
+ serviceWorkers: spec.serviceWorkers,
40
+ });
41
+ const page = await context.newPage();
42
+ const result = { scenario: spec.name, jsErrors: [], consoleErrors: [], failedRequests: [] };
43
+ page.on('pageerror', err => result.jsErrors.push(safe(err)));
44
+ page.on('console', msg => { if (msg.type() === 'error') result.consoleErrors.push(msg.text().slice(0, 260)); });
45
+ page.on('requestfailed', req => { if (result.failedRequests.length < 10) result.failedRequests.push({ path: new URL(req.url()).pathname, reason: req.failure()?.errorText }); });
46
+ try {
47
+ const response = await page.goto(HOST, { waitUntil: 'domcontentloaded', timeout: TIMEOUT });
48
+ result.httpStatus = response?.status() ?? null;
49
+ await page.waitForTimeout(3500);
50
+ result.ui = await page.evaluate(async () => {
51
+ const shell = document.querySelector('.shell');
52
+ const main = document.querySelector('main');
53
+ const box = shell?.getBoundingClientRect();
54
+ const css = shell ? getComputedStyle(shell) : null;
55
+ let serviceWorkerController = false;
56
+ let cacheKeys = [];
57
+ try {
58
+ serviceWorkerController = !!navigator.serviceWorker?.controller;
59
+ cacheKeys = ('caches' in window) ? await caches.keys() : [];
60
+ } catch {}
61
+ return {
62
+ readyState: document.readyState,
63
+ title: document.title, bodyChars: document.body?.innerText.length ?? 0,
64
+ shellExists: !!shell, shellWidth: box?.width ?? 0, shellHeight: box?.height ?? 0,
65
+ shellDisplay: css?.display ?? null, shellVisibility: css?.visibility ?? null,
66
+ mainExists: !!main, mainTextChars: main?.innerText.length ?? 0,
67
+ initialDashboardVisible: document.getElementById('dashboard')?.hidden === false,
68
+ status: document.getElementById('status')?.innerText.slice(0, 180) ?? null,
69
+ serviceWorkerController, cacheKeys
70
+ };
71
+ });
72
+ if (result.httpStatus !== 200 || !result.ui?.shellExists || result.ui?.shellWidth < 50 || result.ui?.bodyChars < 90 || result.jsErrors.length) failed = true;
73
+ } catch (err) {
74
+ failed = true; result.navigationError = safe(err);
75
+ }
76
+ report.sessions.push(result);
77
+ await context.close();
78
+ }
79
+} finally { await browser.close(); }
80
+console.log('CHARTNOVA_PUBLIC_BROWSER_DIAGNOSTIC ' + JSON.stringify(report));
81
+if (failed) process.exitCode = 1;