Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/wxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
53 changes: 53 additions & 0 deletions packages/wxt/src/utils/debug-info.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown> = {
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;
}