// Make Teams see Edge instead of Opera: rewrite UA + client-hint request headers. // Edge UA built from the browser's own UA: the Opera OPR/ token is removed and an Edg/ token is added. const userAgent = navigator.userAgent; // Chrome major version taken from the UA; falls back to 130 if the UA has no Chrome token. const chromeMajor = (userAgent.match(/Chrome\/(\d+)/) || [])[1] || "130"; const edgeUA = userAgent.replace(/ OPR\/[\d.]+/, "") + ` Edg/${chromeMajor}.0.0.0`; // Sec-CH-UA brand list matching the Edge UA; "Not_A Brand" is a GREASE placeholder brand. const brands = `"Microsoft Edge";v="${chromeMajor}", "Chromium";v="${chromeMajor}", "Not_A Brand";v="24"`; // Helper: builds one declarativeNetRequest header operation. const headerSet = (header, value) => ({ header, operation: "set", value }); // Dynamic rules persist across service-worker restarts, so id 1 is replaced on every start. chrome.declarativeNetRequest.updateDynamicRules({ removeRuleIds: [1], addRules: [{ id: 1, // Higher than default so this rule wins over other extensions' header rules. priority: 1, // Rewrite the outgoing request headers. action: { type: "modifyHeaders", requestHeaders: [headerSet("User-Agent", edgeUA), headerSet("Sec-CH-UA", brands)], }, condition: { // Only Teams hosts: teams.microsoft.com and teams.cloud.microsoft. regexFilter: "^https://teams\\.(cloud\\.)?microsoft(\\.com)?/", // Every request type Teams uses, including websocket handshakes. resourceTypes: ["main_frame", "sub_frame", "xmlhttprequest", "script", "stylesheet", "image", "font", "websocket", "other"], }, }], });