| Index: lib/contentFiltering.js |
| =================================================================== |
| --- a/lib/contentFiltering.js |
| +++ b/lib/contentFiltering.js |
| @@ -40,37 +40,43 @@ |
| let userStyleSheetsSupported = true; |
| let snippetsLibrarySource = ""; |
| let executableCode = new Map(); |
| function addStyleSheet(tabId, frameId, styleSheet) |
| { |
| + let details = { |
| + code: styleSheet, |
| + frameId, |
| + matchAboutBlank: true, |
| + runAt: "document_start" |
| + }; |
| + |
| + if (userStyleSheetsSupported) |
| + details.cssOrigin = "user"; |
| + |
| try |
| { |
| - let promise = browser.tabs.insertCSS(tabId, { |
| - code: styleSheet, |
| - cssOrigin: "user", |
| - frameId, |
| - matchAboutBlank: true, |
| - runAt: "document_start" |
| - }); |
| - |
| // See error handling notes in the catch block. |
| - promise.catch(() => {}); |
| + browser.tabs.insertCSS(tabId, details).catch(() => {}); |
| } |
| catch (error) |
| { |
| // If the error is about the "cssOrigin" option, this is an older version |
| // of Chromium (65 and below) or Firefox (52 and below) that does not |
| // support user style sheets. |
| - if (/\bcssOrigin\b/.test(error.message)) |
| + if (userStyleSheetsSupported && /\bcssOrigin\b/.test(error.message)) |
| + { |
| userStyleSheetsSupported = false; |
| + return addStyleSheet(tabId, frameId, styleSheet); |
| + } |
| + |
| // For other errors, we simply return false to indicate failure. |
| // |
| // One common error that occurs frequently is when a frame is not found |
| // (e.g. "Error: No frame with id 574 in tab 266"), which can happen when |
| // the code in the parent document has removed the frame before the |
| // background page has had a chance to respond to the content script's |
| // "content.applyFilters" message. We simply ignore such errors, because |
| // otherwise they show up in the log too often and make debugging |
| @@ -194,17 +200,16 @@ |
| } |
| } |
| port.on("content.applyFilters", (message, sender) => |
| { |
| let selectors = []; |
| let emulatedPatterns = []; |
| let trace = HitLogger.hasListener(sender.page.id); |
| - let inline = !userStyleSheetsSupported; |
| let {elemhide, snippets} = message.filterTypes || |
| {elemhide: true, snippets: true}; |
| if (!checkWhitelisted(sender.page, sender.frame, null, |
| RegExpFilter.typeMap.DOCUMENT)) |
| { |
| let docDomain = extractHostFromFrame(sender.frame); |
| @@ -235,33 +240,22 @@ |
| RegExpFilter.typeMap.GENERICHIDE); |
| selectors = ElemHide.getSelectorsForDomain(docDomain, specificOnly); |
| for (let filter of ElemHideEmulation.getRulesForDomain(docDomain)) |
| emulatedPatterns.push({selector: filter.selector, text: filter.text}); |
| } |
| } |
| - if (!inline && !updateFrameStyles(sender.page.id, sender.frame.id, |
| - selectors, "standard")) |
| - { |
| - inline = true; |
| - } |
| + updateFrameStyles(sender.page.id, sender.frame.id, selectors, "standard"); |
| - let response = {trace, inline, emulatedPatterns}; |
| - if (trace || inline) |
| + let response = {trace, emulatedPatterns}; |
| + if (trace) |
| response.selectors = selectors; |
| - // If we can't remove user style sheets using tabs.removeCSS, we'll only keep |
| - // adding them, which could cause problems with emulation filters as |
| - // described in issue #5864. Instead, we can just ask the content script to |
| - // add styles for emulation filters inline. |
| - if (!styleSheetRemovalSupported) |
| - response.inlineEmulated = true; |
| - |
| return response; |
| }); |
| port.on("elemhide.injectSelectors", (message, sender) => |
| { |
| updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, |
| message.groupName, message.appendOnly); |
| }); |