|
34 | 34 |
|
35 | 35 | let _lastPolicy; |
36 | 36 |
|
| 37 | + const dnrTypes = Object.values(browser.declarativeNetRequest.ResourceType); |
37 | 38 | const resourceTypesMap = {}; |
38 | | - { |
39 | | - const dnrTypes = Object.values(browser.declarativeNetRequest.ResourceType); |
40 | | - |
41 | | - for(const [key, value] of Object.entries(RequestGuard.policyTypesMap)) { |
42 | | - if (!(value && dnrTypes.includes(key))) continue; |
43 | | - const mapping = resourceTypesMap[value] ||= []; |
44 | | - mapping.push(key); |
45 | | - } |
| 39 | + for(const [key, value] of Object.entries(RequestGuard.policyTypesMap)) { |
| 40 | + if (!(value && dnrTypes.includes(key))) continue; |
| 41 | + const mapping = resourceTypesMap[value] ||= []; |
| 42 | + mapping.push(key); |
46 | 43 | } |
47 | 44 |
|
48 | 45 | const ResourceTypeFor = { |
|
184 | 181 |
|
185 | 182 | async function addTabRules(rules = []) { |
186 | 183 | if (ns.unrestrictedTabs.size) { |
| 184 | + const tabIds = [...ns.unrestrictedTabs]; |
| 185 | + tabIds.push(browser.tabs.TAB_ID_NONE); // for service workers |
187 | 186 | rules.push({ |
188 | 187 | id: TAB_BASE, |
189 | 188 | priority: TAB_PRIORITY, |
190 | 189 | action: { |
191 | 190 | type: "allowAllRequests", |
192 | 191 | }, |
193 | 192 | condition: { |
194 | | - tabIds: [...ns.unrestrictedTabs], |
| 193 | + tabIds, |
195 | 194 | resourceTypes: ["main_frame", "sub_frame"], |
196 | 195 | } |
197 | 196 | }); |
| 197 | + rules.push({ |
| 198 | + id: TAB_BASE + 1, |
| 199 | + priority: TAB_PRIORITY, |
| 200 | + action: { |
| 201 | + type: "allow", |
| 202 | + }, |
| 203 | + condition: { |
| 204 | + tabIds, |
| 205 | + resourceTypes: dnrTypes, |
| 206 | + } |
| 207 | + }); |
198 | 208 | } |
199 | 209 | await addCtxRules(rules); |
200 | 210 | return rules; |
|
223 | 233 | const urlFilter = toUrlFilter(siteKey); |
224 | 234 | for (const [capsKey, tabIds] of [...caps2Tabs]) { |
225 | 235 | forBlockAllow(new Set(JSON.parse(capsKey)), (type, resourceTypes) => { |
| 236 | + if (type == "allow" && resourceTypes.includes("script")) { |
| 237 | + tabIds.push(browser.tabs.TAB_ID_NONE); // for service workers |
| 238 | + } |
226 | 239 | rules.push({ |
227 | 240 | id: TAB_BASE + rules.length, |
228 | 241 | priority: CTX_PRIORITY, |
|
0 commit comments