text-transformer / scripts /debug-space.js
OnyxlMunkey's picture
Fix: use same-origin proxy for HF inference (avoid CORS)
cc036eb
/**
* 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);
});