|
| 1 | +// filepath: extension/entrypoints/utils/firefox-debug.ts |
| 2 | + |
| 3 | +/** |
| 4 | + * Firefox-specific debugging utilities. |
| 5 | + * Helps diagnose Firefox-only issues in the extension. |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * Detect if the current browser is Firefox. |
| 10 | + */ |
| 11 | +export function isFirefox(): boolean { |
| 12 | + return typeof navigator !== 'undefined' && |
| 13 | + /Firefox/i.test(navigator.userAgent); |
| 14 | +} |
| 15 | + |
| 16 | +/** |
| 17 | + * Log a debug message only when running in Firefox. |
| 18 | + */ |
| 19 | +export function logFirefox(category: string, message: string, data?: unknown): void { |
| 20 | + if (!isFirefox()) return; |
| 21 | + |
| 22 | + const prefix = `[CQD:Firefox:${category}]`; |
| 23 | + if (data !== undefined) { |
| 24 | + console.log(prefix, message, data); |
| 25 | + } else { |
| 26 | + console.log(prefix, message); |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +/** |
| 31 | + * Log a warning message only when running in Firefox. |
| 32 | + */ |
| 33 | +export function warnFirefox(category: string, message: string, data?: unknown): void { |
| 34 | + if (!isFirefox()) return; |
| 35 | + |
| 36 | + const prefix = `[CQD:Firefox:${category}]`; |
| 37 | + if (data !== undefined) { |
| 38 | + console.warn(prefix, message, data); |
| 39 | + } else { |
| 40 | + console.warn(prefix, message); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +/** |
| 45 | + * Check if Firefox's Promise-based messaging API is available. |
| 46 | + * Returns true if sendMessage returns a Promise (Firefox behavior). |
| 47 | + */ |
| 48 | +export function hasPromiseBasedMessaging(): boolean { |
| 49 | + if (typeof chrome === 'undefined' || !chrome.runtime?.sendMessage) { |
| 50 | + return false; |
| 51 | + } |
| 52 | + |
| 53 | + // In Firefox, sendMessage can return a Promise even in MV2 |
| 54 | + // We detect this by checking the browser's user agent |
| 55 | + return isFirefox(); |
| 56 | +} |
0 commit comments