ext: spoof Edge UA/client hints for Teams

This commit is contained in:
Stefano Zini
2026-11-04 10:55:14 +01:00
parent 71b0d39b2a
commit 654825ad67
3 changed files with 57 additions and 3 deletions
+28
View File
@@ -0,0 +1,28 @@
// MAIN world, document_start: navigator.* reports Edge instead of Opera.
(() => {
const ua = navigator.userAgent;
if (!/OPR\//.test(ua)) return;
const v = (ua.match(/Chrome\/(\d+)/) || [])[1] || "130";
const edgeUA = ua.replace(/ OPR\/[\d.]+/, "") + ` Edg/${v}.0.0.0`;
const fix = (b) => b.map((x) => (/opera/i.test(x.brand) ? { brand: "Microsoft Edge", version: x.version } : x));
const def = (o, k, g) => Object.defineProperty(o, k, { get: g, configurable: true });
def(Navigator.prototype, "userAgent", () => edgeUA);
def(Navigator.prototype, "appVersion", () => edgeUA.replace(/^Mozilla\//, ""));
const d = navigator.userAgentData;
if (!d) return;
const brands = fix(d.brands);
const hev = d.getHighEntropyValues.bind(d);
const patched = {
brands,
mobile: d.mobile,
platform: d.platform,
getHighEntropyValues: async (h) => {
const r = await hev(h);
if (r.brands) r.brands = fix(r.brands);
if (r.fullVersionList) r.fullVersionList = fix(r.fullVersionList);
return r;
},
toJSON: () => ({ brands, mobile: d.mobile, platform: d.platform }),
};
def(Navigator.prototype, "userAgentData", () => patched);
})();