{"record":{"id":"2db4dccce5596eaa","repo":"garrytan/gstack","slug":"download-failed-failure","errorCode":null,"errorMessage":"Download failed: ${failure}","messagePattern":"Download failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"browse/src/write-commands.ts","lineNumber":1226,"sourceCode":"        contentType = match[1];\n        buffer = Buffer.from(match[2], 'base64');\n      } else if (useNavigate) {\n        // Strategy 2: Navigate to URL and capture browser-triggered download.\n        // Handles URLs that trigger file downloads via redirects,\n        // Content-Disposition headers, or anti-bot CDN chains where\n        // page.request.fetch() can't follow the auth/redirect chain.\n        await validateNavigationUrl(url);\n        const downloadPromise = page.waitForEvent('download', { timeout: 60000 });\n        // Use goto with 'commit' wait — the page may redirect to trigger\n        // the download, so 'domcontentloaded' may never fire.\n        page.goto(url, { waitUntil: 'commit', timeout: 30000 }).catch(() => {\n          // Navigation may \"fail\" because the response is a download,\n          // not a page. The download event handles it.\n        });\n        const download = await downloadPromise;\n        const failure = await download.failure();\n        if (failure) {\n          throw new Error(`Download failed: ${failure}`);\n        }\n        // Save to temp location first, then read into buffer\n        const tempPath = path.join(TEMP_DIR, `browse-nav-download-${Date.now()}`);\n        await download.saveAs(tempPath);\n        buffer = fs.readFileSync(tempPath);\n        // Try to infer content type from suggested filename\n        const suggested = download.suggestedFilename();\n        if (suggested) {\n          const extMatch = suggested.match(/\\.([a-z0-9]+)$/i);\n          if (extMatch) {\n            const extLower = extMatch[1].toLowerCase();\n            const mimeMap: Record<string, string> = {\n              epub: 'application/epub+zip', pdf: 'application/pdf',\n              zip: 'application/zip', gz: 'application/gzip',\n              mp3: 'audio/mpeg', mp4: 'video/mp4',\n              jpg: 'image/jpeg', jpeg: 'image/jpeg', png: 'image/png',\n              txt: 'text/plain', html: 'text/html', json: 'application/json',\n            };","sourceCodeStart":1208,"sourceCodeEnd":1244,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/write-commands.ts#L1208-L1244","documentation":"Error \"Download failed: ${failure}\" thrown in garrytan/gstack.","triggerScenarios":"Thrown at browse/src/write-commands.ts:1226 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}