* Get the browser extension API (chrome or browser). * Returns undefined if not running in an extension context (ISOLATED world).
()
| 33 | * Returns undefined if not running in an extension context (ISOLATED world). |
| 34 | */ |
| 35 | function getBrowserAPI(): typeof chrome | undefined { |
| 36 | try { |
| 37 | // @ts-expect-error: browser may not be defined in all environments |
| 38 | const candidateBrowser = typeof browser !== "undefined" ? browser : undefined; |
| 39 | if (candidateBrowser && typeof candidateBrowser.runtime?.sendMessage === "function") { |
| 40 | return candidateBrowser; |
| 41 | } |
| 42 | const candidateChrome = typeof chrome !== "undefined" ? chrome : undefined; |
| 43 | if (candidateChrome && typeof candidateChrome.runtime?.sendMessage === "function") { |
| 44 | return candidateChrome; |
| 45 | } |
| 46 | } catch { |
| 47 | // Not in extension context |
| 48 | } |
| 49 | return undefined; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Check if running in Office Add-in environment |
no outgoing calls
no test coverage detected