File size: 3,008 Bytes
cc036eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
 * Playwright script: open HF Space, trigger TinyLlama, capture console/network errors.
 * Run: node scripts/debug-space.js
 * Or with auth URL: SPACE_URL="https://user:TOKEN@huggingface.co/spaces/OnyxMunk/text-transformer" node scripts/debug-space.js
 */
const { chromium } = require('playwright');

const SPACE_URL = process.env.SPACE_URL || 'https://huggingface.co/spaces/OnyxMunk/text-transformer';

async function main() {
  const browser = await chromium.launch({ headless: false });
  const context = await browser.newContext();
  const consoleLogs = [];
  const requestFailures = [];

  context.on('console', (msg) => {
    const text = msg.text();
    const type = msg.type();
    consoleLogs.push({ type, text });
    if (type === 'error' || text.toLowerCase().includes('failed') || text.toLowerCase().includes('cors')) {
      console.error(`[CONSOLE ${type}]`, text);
    }
  });

  context.on('requestfailed', (request) => {
    const failure = { url: request.url(), failure: request.failure()?.errorText };
    requestFailures.push(failure);
    console.error('[REQUEST FAILED]', failure.url, failure.failure);
  });

  const page = await context.newPage();
  await page.goto(SPACE_URL, { waitUntil: 'domcontentloaded', timeout: 60000 }).catch((e) => {
    console.error('Navigate error:', e.message);
  });

  await page.waitForTimeout(5000);

  const snapshot = await page.content();
  if (snapshot.includes('Failed to connect') || snapshot.includes('CORS') || snapshot.includes('error')) {
    const match = snapshot.match(/>([^<]*(?:Failed to connect|CORS|error)[^<]*)</);
    if (match) console.error('Page contains error text:', match[1].trim().slice(0, 200));
  }

  const tinyLlamaTab = page.locator('button, [role="tab"], a').filter({ hasText: /TinyLlama|Tiny Llama/i }).first();
  if (await tinyLlamaTab.count() > 0) {
    await tinyLlamaTab.click();
    await page.waitForTimeout(1500);
    const promptInput = page.locator('textarea[placeholder*="TinyLlama"], textarea[id="llama-input"], textarea').first();
    if (await promptInput.count() > 0) {
      await promptInput.fill('Hello');
      await page.waitForTimeout(500);
      const generateBtn = page.locator('button[title="Generate Response"], button').filter({ hasText: /Generate|⚡/ }).first();
      if (await generateBtn.count() > 0) {
        await generateBtn.click();
        await page.waitForTimeout(8000);
      }
    }
  }

  const errorEl = page.locator('text=/Failed to connect|CORS|error/i').first();
  if (await errorEl.count() > 0) {
    console.error('Visible error on page:', await errorEl.textContent());
  }

  console.log('\n--- Console messages (errors/warnings) ---');
  consoleLogs.filter((m) => m.type === 'error' || m.type === 'warning').forEach((m) => console.log(m.type, m.text));
  console.log('\n--- Failed network requests ---');
  requestFailures.forEach((f) => console.log(f.url, f.failure));

  await browser.close();
}

main().catch((e) => {
  console.error(e);
  process.exit(1);
});