fix(studio): prevent browser launch timeout from crashing dev server

The shared Puppeteer browser pool in getSharedBrowser() could throw a
30s TimeoutError during launch. This error propagated as an uncaught
rejection and killed the vite process, even though generateThumbnail
had its own try/catch — the browser launch promise rejected outside
that scope. Now getSharedBrowser itself catches launch failures and
returns null, so thumbnails degrade gracefully instead of crashing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Miguel Ángel
2026-05-10 18:40:52 +00:00
co-authored by Claude Opus 4.6
parent 52674dfd86
commit a886e70b28
+23 -14
View File
@@ -34,20 +34,29 @@ async function getSharedBrowser(): Promise<import("puppeteer-core").Browser | nu
if (_browser?.connected) return _browser;
if (_browserLaunchPromise) return _browserLaunchPromise;
_browserLaunchPromise = (async () => {
const puppeteer = await import("puppeteer-core");
const executablePath = [
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
"/usr/bin/google-chrome",
"/usr/bin/chromium-browser",
].find((p) => existsSync(p));
if (!executablePath) return null;
_browser = await puppeteer.default.launch({
headless: true,
executablePath,
args: ["--no-sandbox", "--disable-gpu", "--disable-dev-shm-usage"],
});
_browserLaunchPromise = null;
return _browser;
try {
const puppeteer = await import("puppeteer-core");
const executablePath = [
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
"/usr/bin/google-chrome",
"/usr/bin/chromium-browser",
].find((p) => existsSync(p));
if (!executablePath) return null;
_browser = await puppeteer.default.launch({
headless: true,
executablePath,
args: ["--no-sandbox", "--disable-gpu", "--disable-dev-shm-usage"],
});
return _browser;
} catch (err) {
console.warn(
"[Studio] Browser launch failed — thumbnails will be unavailable:",
err instanceof Error ? err.message : err,
);
return null;
} finally {
_browserLaunchPromise = null;
}
})();
return _browserLaunchPromise;
}