From d10ceb787b994f677549871a78c45c562ed908bd Mon Sep 17 00:00:00 2001 From: SysAdmin Date: Tue, 17 Mar 2026 02:12:52 +0000 Subject: [PATCH] debug(schematics): add HTML logging for download page diagnosis Add debug logging to dump page titles, HTML lengths, and snippets when the schematic download page is loaded. Also switch to waitUntil: 'load' and add 3s delay for async JS execution. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/schematics-browser.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/schematics-browser.js b/src/schematics-browser.js index 6cac02e..6cf1fe2 100644 --- a/src/schematics-browser.js +++ b/src/schematics-browser.js @@ -193,14 +193,23 @@ export async function downloadSchematic(projectUrl, timeoutMs = 60000) { // Step 2: Navigate to download page (worldmap has the Schemagic embed with the real URL) const downloadPageUrl = projectUrl.replace(/\/?$/, '/download/worldmap/'); log(TAG, `Navigating to download page: ${downloadPageUrl}`); - await page.goto(downloadPageUrl, { waitUntil: 'domcontentloaded', timeout: timeoutMs }); + await page.goto(downloadPageUrl, { waitUntil: 'load', timeout: timeoutMs }); await waitForCloudflare(page, timeoutMs); + // Give JS time to execute (Schemagic embeds may load async) + await page.waitForTimeout(3000); // Step 3: Extract schematic URL from Schemagic.load() JS call or element let schematicUrl = null; // 3a: Look for Schemagic.load({ schematic: "https://...resource_media/schematic/..." }) const html = await page.content(); + // Debug: Log page title and HTML snippet to diagnose extraction failures + const pageTitle = await page.title(); + log(TAG, `Download page title: "${pageTitle}", HTML length: ${html.length}`); + log(TAG, `HTML snippet (first 500): ${html.slice(0, 500).replace(/\n/g, ' ')}`); + // Check for any download-related links + const allHrefs = html.match(/href="[^"]*download[^"]*"/gi) || []; + log(TAG, `Download-related hrefs found: ${allHrefs.length} — ${allHrefs.slice(0, 5).join(', ')}`); const schemagicMatch = html.match(/Schemagic\.load\s*\(\s*\{[^}]*schematic:\s*"([^"]+)"/); if (schemagicMatch) { schematicUrl = schemagicMatch[1]; @@ -232,10 +241,14 @@ export async function downloadSchematic(projectUrl, timeoutMs = 60000) { if (!schematicUrl) { const schematicPageUrl = projectUrl.replace(/\/?$/, '/download/schematic/'); log(TAG, `Trying schematic download page: ${schematicPageUrl}`); - await page.goto(schematicPageUrl, { waitUntil: 'domcontentloaded', timeout: timeoutMs }); + await page.goto(schematicPageUrl, { waitUntil: 'load', timeout: timeoutMs }); await waitForCloudflare(page, timeoutMs); + await page.waitForTimeout(3000); const schematicHtml = await page.content(); + const schPageTitle = await page.title(); + log(TAG, `Schematic page title: "${schPageTitle}", HTML length: ${schematicHtml.length}`); + log(TAG, `Schematic page HTML snippet (first 500): ${schematicHtml.slice(0, 500).replace(/\n/g, ' ')}`); const schematicPageMatch = schematicHtml.match(/Schemagic\.load\s*\(\s*\{[^}]*schematic:\s*"([^"]+)"/); if (schematicPageMatch) { schematicUrl = schematicPageMatch[1];