Report a problem: the webview's full version (the user agent carries a reduced one)

Seen live: the report said "WebView2 154.0.0.0", Chromium's reduced user agent version. The engine's brand list (`fullVersionList`) gives the full one, which the report now uses when it is a plain version (tested).
This commit is contained in:
CRTkafa 2026-10-01 03:56:18 +07:00
parent 25f84a932f
commit fd6ae707ca
3 changed files with 15 additions and 6 deletions

View file

@ -16,13 +16,13 @@ import { safe } from './safeStore.ts';
import { site } from './site.ts'; import { site } from './site.ts';
import { setOverlay } from './state.ts'; import { setOverlay } from './state.ts';
type Hints = { platformVersion?: string; architecture?: string; bitness?: string }; type Hints = { platformVersion?: string; architecture?: string; bitness?: string; fullVersionList?: Array<{ brand?: string; version?: string }> };
/** What the engine says about the system when asked (Chromium webviews; others have the user agent only). */ /** What the engine says about the system when asked (Chromium webviews; others have the user agent only). */
async function systemHints(): Promise<Hints> { async function systemHints(): Promise<Hints> {
try { try {
const data = (navigator as Navigator & { userAgentData?: { getHighEntropyValues(hints: string[]): Promise<Hints> } }).userAgentData; const data = (navigator as Navigator & { userAgentData?: { getHighEntropyValues(hints: string[]): Promise<Hints> } }).userAgentData;
return data ? await data.getHighEntropyValues(['platformVersion', 'architecture', 'bitness']) : {}; return data ? await data.getHighEntropyValues(['platformVersion', 'architecture', 'bitness', 'fullVersionList']) : {};
} catch { return {}; } } catch { return {}; }
} }
@ -45,7 +45,7 @@ async function collect(): Promise<ReportInfo> {
product: config.product, product: config.product,
appVersion, appVersion,
system: systemFromUserAgent(navigator.userAgent, hints), system: systemFromUserAgent(navigator.userAgent, hints),
webview: webviewFromUserAgent(navigator.userAgent), webview: webviewFromUserAgent(navigator.userAgent, hints.fullVersionList),
language: menu.languages?.state().locale ?? textLocale(), language: menu.languages?.state().locale ?? textLocale(),
languageChoice: menu.languages?.state().preference ?? 'fixed', languageChoice: menu.languages?.state().preference ?? 'fixed',
mode, mode,

View file

@ -90,10 +90,14 @@ export function buildReport(info: ReportInfo): string {
return lines.join('\n'); return lines.join('\n');
} }
/** The webview engine and its version from a user agent string. */ /**
export function webviewFromUserAgent(userAgent: string): string { * The webview engine and its version from a user agent string. Chromium reduces the version in the
* user agent ("154.0.0.0"); the full one comes from the engine's brand list when it gives one.
*/
export function webviewFromUserAgent(userAgent: string, brands: ReadonlyArray<{ brand?: string; version?: string }> = []): string {
const full = brands.find(entry => /WebView2|Microsoft Edge/.test(entry.brand ?? '') && /^[\d.]+$/.test(entry.version ?? ''));
const edge = /\bEdg\/([\d.]+)/.exec(userAgent); const edge = /\bEdg\/([\d.]+)/.exec(userAgent);
if (edge) return `WebView2 ${edge[1]}`; if (edge) return `WebView2 ${full?.version ?? edge[1]}`;
const chrome = /\bChrom(?:e|ium)\/([\d.]+)/.exec(userAgent); const chrome = /\bChrom(?:e|ium)\/([\d.]+)/.exec(userAgent);
if (chrome) return `Chromium ${chrome[1]}`; if (chrome) return `Chromium ${chrome[1]}`;
const webkit = /\bAppleWebKit\/([\d.]+)/.exec(userAgent); const webkit = /\bAppleWebKit\/([\d.]+)/.exec(userAgent);

View file

@ -99,6 +99,11 @@ test('the framework version is the package version', () => {
test('the system and the webview are read coarsely from the user agent', () => { test('the system and the webview are read coarsely from the user agent', () => {
const edge = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.3537.71'; const edge = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.3537.71';
assert.equal(webviewFromUserAgent(edge), 'WebView2 141.0.3537.71'); assert.equal(webviewFromUserAgent(edge), 'WebView2 141.0.3537.71');
// A reduced user agent (seen live: "154.0.0.0") and the engine's brand list with the full version.
const reduced = edge.replace('141.0.3537.71', '154.0.0.0');
assert.equal(webviewFromUserAgent(reduced), 'WebView2 154.0.0.0');
assert.equal(webviewFromUserAgent(reduced, [{ brand: 'Chromium', version: '154.0.7000.1' }, { brand: 'Microsoft Edge WebView2', version: '154.0.3700.12' }]), 'WebView2 154.0.3700.12');
assert.equal(webviewFromUserAgent(reduced, [{ brand: 'Microsoft Edge WebView2', version: '154; drop' }]), 'WebView2 154.0.0.0');
assert.equal(systemFromUserAgent(edge), 'Windows 10 or 11 (x64)'); assert.equal(systemFromUserAgent(edge), 'Windows 10 or 11 (x64)');
assert.equal(systemFromUserAgent(edge, { platformVersion: '15.0.0', architecture: 'x86', bitness: '64' }), 'Windows 11 (x86_64)'); assert.equal(systemFromUserAgent(edge, { platformVersion: '15.0.0', architecture: 'x86', bitness: '64' }), 'Windows 11 (x86_64)');
assert.equal(systemFromUserAgent(edge, { platformVersion: '10.0.0' }), 'Windows 10 (x64)'); assert.equal(systemFromUserAgent(edge, { platformVersion: '10.0.0' }), 'Windows 10 (x64)');