import { Tooltip } from 'antd'; import React, { type ReactNode, useState } from 'react'; // Keep this in sync with apps/studio/package.json. The test verifies the // relationship so a Puppeteer upgrade cannot leave users with a stale command. export const STUDIO_PUPPETEER_VERSION = '24.43.1'; const INSTALL_CHROME_COMMAND = `npx puppeteer@${STUDIO_PUPPETEER_VERSION} browsers install chrome`; const PUPPETEER_CONFIGURATION_URL = 'https://pptr.dev/guides/configuration'; const CHROME_MISSING_RE = /could not find (?:google )?chrome/; interface CreateAgentErrorNotification { title: string; description: ReactNode; duration: number; } function getErrorMessage(error: unknown): string { if (error instanceof Error) { return error.message || error.toString(); } if (typeof error === 'string') { return error; } if (error && typeof error === 'object' && 'message' in error) { const value = (error as { message?: unknown }).message; if (typeof value === 'string') { return value; } } return String(error); } export function getPuppeteerChromeInstallCommand(): string { return INSTALL_CHROME_COMMAND; } function copyInstallCommand(command: string) { if (typeof navigator === 'undefined') { return; } try { void navigator.clipboard?.writeText(command).catch(() => undefined); } catch { // Clipboard access can be unavailable or denied; copying is best-effort. } } function CopyIcon() { return ( ); } export function isPuppeteerChromeMissingError(error: unknown): boolean { const message = getErrorMessage(error).toLowerCase(); return ( CHROME_MISSING_RE.test(message) && (message.includes('puppeteer browsers install chrome') || message.includes('cache path') || message.includes('puppeteer')) ); } function ChromeMissingDescription({ error }: { error: unknown }) { const rawMessage = getErrorMessage(error); const installCommand = getPuppeteerChromeInstallCommand(); const [copyVisible, setCopyVisible] = useState(false); return (
{installCommand}
{rawMessage}
}
zIndex={10_000}
>