diff --git a/app/ext/background.js b/app/ext/background.js new file mode 100644 index 0000000..fbfea46 --- /dev/null +++ b/app/ext/background.js @@ -0,0 +1,22 @@ +// Make Teams see Edge instead of Opera: rewrite UA + client-hint request headers. +const ua = navigator.userAgent; +const v = (ua.match(/Chrome\/(\d+)/) || [])[1] || "130"; +const edgeUA = ua.replace(/ OPR\/[\d.]+/, "") + ` Edg/${v}.0.0.0`; +const brands = `"Microsoft Edge";v="${v}", "Chromium";v="${v}", "Not_A Brand";v="24"`; +const set = (header, value) => ({ header, operation: "set", value }); + +chrome.declarativeNetRequest.updateDynamicRules({ + removeRuleIds: [1], + addRules: [{ + id: 1, + priority: 1, + action: { + type: "modifyHeaders", + requestHeaders: [set("User-Agent", edgeUA), set("Sec-CH-UA", brands)], + }, + condition: { + regexFilter: "^https://teams\\.(cloud\\.)?microsoft(\\.com)?/", + resourceTypes: ["main_frame", "sub_frame", "xmlhttprequest", "script", "stylesheet", "image", "font", "websocket", "other"], + }, + }], +}); diff --git a/app/ext/manifest.json b/app/ext/manifest.json index 60dadbd..65395e7 100644 --- a/app/ext/manifest.json +++ b/app/ext/manifest.json @@ -3,8 +3,12 @@ "name": "Teams Whisper Recorder", "version": "1.1", "description": "Record Teams tab audio+video (+mic) and transcribe with local whisper server", - "permissions": ["tabCapture", "offscreen", "activeTab", "tabs"], - "host_permissions": ["http://127.0.0.1:18765/*"], - "content_scripts": [{ "matches": ["https://teams.cloud.microsoft/*", "https://teams.microsoft.com/*"], "js": ["teams.js"], "run_at": "document_idle" }], + "permissions": ["tabCapture", "offscreen", "activeTab", "tabs", "declarativeNetRequest"], + "host_permissions": ["http://127.0.0.1:18765/*", "https://teams.cloud.microsoft/*", "https://teams.microsoft.com/*"], + "background": { "service_worker": "background.js" }, + "content_scripts": [ + { "matches": ["https://teams.cloud.microsoft/*", "https://teams.microsoft.com/*"], "js": ["spoof.js"], "run_at": "document_start", "world": "MAIN", "all_frames": true }, + { "matches": ["https://teams.cloud.microsoft/*", "https://teams.microsoft.com/*"], "js": ["teams.js"], "run_at": "document_idle" } + ], "action": { "default_popup": "popup.html" } } diff --git a/app/ext/spoof.js b/app/ext/spoof.js new file mode 100644 index 0000000..4badb55 --- /dev/null +++ b/app/ext/spoof.js @@ -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); +})();