Add explanatory comments across codebase

This commit is contained in:
Stefano Zini
2026-11-04 14:23:18 +01:00
parent b8aa5548a2
commit 82b72b6c28
34 changed files with 934 additions and 0 deletions
+9
View File
@@ -1,21 +1,30 @@
// 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 ua = navigator.userAgent;
// Chrome major version taken from the UA; falls back to 130 if the UA has no Chrome token.
const v = (ua.match(/Chrome\/(\d+)/) || [])[1] || "130";
const edgeUA = ua.replace(/ OPR\/[\d.]+/, "") + ` Edg/${v}.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="${v}", "Chromium";v="${v}", "Not_A Brand";v="24"`;
// Helper: builds one declarativeNetRequest header operation.
const set = (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: [set("User-Agent", edgeUA), set("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"],
},
}],