29 lines
1.2 KiB
JavaScript
29 lines
1.2 KiB
JavaScript
// 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);
|
|
})();
|