diff --git a/packages/wxt/package.json b/packages/wxt/package.json index f479d64d7..7e1ed22f4 100644 --- a/packages/wxt/package.json +++ b/packages/wxt/package.json @@ -135,6 +135,10 @@ "types": "./dist/utils/content-script-context.d.mts", "default": "./dist/utils/content-script-context.mjs" }, + "./utils/debug-info": { + "types": "./dist/utils/debug-info.d.mts", + "default": "./dist/utils/debug-info.mjs" + }, "./utils/content-script-ui/types": { "types": "./dist/utils/content-script-ui/types.d.mts", "default": "./dist/utils/content-script-ui/types.mjs" diff --git a/packages/wxt/src/utils/debug-info.ts b/packages/wxt/src/utils/debug-info.ts new file mode 100644 index 000000000..33a9a4665 --- /dev/null +++ b/packages/wxt/src/utils/debug-info.ts @@ -0,0 +1,53 @@ +/** @module wxt/utils/debug-info */ +import { browser } from 'wxt/browser'; + +/** + * Collect debug information about the current browser and platform. + * + * @example + * ```ts + * const info = await getDebugInfo(); + * // { + * // "extensionVersion": "1.0.0", + * // "browser": [ + * // { + * // "brand": "Google Chrome", + * // "version": "..." + * // }, + * // { + * // "brand": "Chromium", + * // "version": "..." + * // } + * // ], + * // "platform": { + * // "os": "Windows", + * // "arch": "x86" + * // } + * // } + * ```; + */ +export async function getDebugInfo() { + const debugInfo: Record = { + extensionVersion: browser.runtime.getManifest().version, + }; + + if (import.meta.env.FIREFOX) { + // @ts-ignore + debugInfo.browser = await browser.runtime.getBrowserInfo(); + debugInfo.platform = await browser.runtime.getPlatformInfo(); + } + + if (import.meta.env.CHROME) { + // @ts-ignore + const ua = await navigator.userAgentData.getHighEntropyValues([ + 'fullVersionList', + 'architecture', + 'platform', + ]); + + debugInfo.browser = ua.fullVersionList; + debugInfo.platform = { os: ua.platform, arch: ua.architecture }; + } + + return debugInfo; +}