()
| 161 | let _thumbnailBrowserInitializing: Promise<import("puppeteer-core").Browser | null> | null = null; |
| 162 | |
| 163 | async function getThumbnailBrowser(): Promise<import("puppeteer-core").Browser | null> { |
| 164 | if (_thumbnailBrowser?.connected) return _thumbnailBrowser; |
| 165 | if (_thumbnailBrowserInitializing) return _thumbnailBrowserInitializing; |
| 166 | |
| 167 | _thumbnailBrowserInitializing = (async () => { |
| 168 | try { |
| 169 | const { ensureBrowser } = await import("../browser/manager.js"); |
| 170 | const { acquireBrowser, buildChromeArgs } = await import("@hyperframes/engine"); |
| 171 | |
| 172 | try { |
| 173 | const b = await ensureBrowser(); |
| 174 | if (b.executablePath && !process.env.PRODUCER_HEADLESS_SHELL_PATH) { |
| 175 | process.env.PRODUCER_HEADLESS_SHELL_PATH = b.executablePath; |
| 176 | } |
| 177 | } catch { |
| 178 | /* continue — acquireBrowser will try its own resolution */ |
| 179 | } |
| 180 | |
| 181 | const acquired = await acquireBrowser( |
| 182 | buildChromeArgs({ width: 1920, height: 1080, captureMode: "screenshot" }), |
| 183 | { forceScreenshot: true }, |
| 184 | ); |
| 185 | _thumbnailBrowser = acquired.browser; |
| 186 | _thumbnailBrowser.on("disconnected", () => { |
| 187 | _thumbnailBrowser = null; |
| 188 | _thumbnailBrowserInitializing = null; |
| 189 | }); |
| 190 | return _thumbnailBrowser; |
| 191 | } catch (err) { |
| 192 | console.warn( |
| 193 | "[Studio] Failed to launch thumbnail browser:", |
| 194 | err instanceof Error ? err.message : err, |
| 195 | ); |
| 196 | _thumbnailBrowserInitializing = null; |
| 197 | return null; |
| 198 | } |
| 199 | })(); |
| 200 | |
| 201 | return _thumbnailBrowserInitializing; |
| 202 | } |
| 203 | |
| 204 | export async function closeThumbnailBrowser(): Promise<void> { |
| 205 | if (!_thumbnailBrowser) return; |
no test coverage detected