Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/cssInjection.js

Issue 29720585: Noissue - Explicitly ignore asynchronous errors from tabs.insertCSS (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Add comments Created March 13, 2018, 5:11 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 function addStyleSheet(tabId, frameId, styleSheet) 69 function addStyleSheet(tabId, frameId, styleSheet)
70 { 70 {
71 try 71 try
72 { 72 {
73 browser.tabs.insertCSS(tabId, { 73 browser.tabs.insertCSS(tabId, {
74 code: styleSheet, 74 code: styleSheet,
75 cssOrigin: "user", 75 cssOrigin: "user",
76 frameId, 76 frameId,
77 matchAboutBlank: true, 77 matchAboutBlank: true,
78 runAt: "document_start" 78 runAt: "document_start"
79 }); 79 })
80 // Some errors are asynchronous (e.g. frame-not-found on Chromium 66). We
81 // can simply ignore any such errors.
82 .catch(() => {});
80 } 83 }
81 catch (error) 84 catch (error)
82 { 85 {
86 // If the error is about the "cssOrigin" option, this is an older version
87 // of Chromium (65 and below) or Firefox (52 and below) that does not
88 // support user style sheets.
83 if (/\bcssOrigin\b/.test(error.message)) 89 if (/\bcssOrigin\b/.test(error.message))
84 userStyleSheetsSupported = false; 90 userStyleSheetsSupported = false;
85 91
92 // Sometimes a frame gets removed from the document between the time the
93 // content script sends the "elemhide.getSelectors" message and the time
94 // the background page tries to inject a style sheet, which causes
95 // tabs.insertCSS to throw a frame-not-found error. We must handle any such
96 // errors.
86 return false; 97 return false;
87 } 98 }
88 99
89 return true; 100 return true;
90 } 101 }
91 102
92 function removeStyleSheet(tabId, frameId, styleSheet) 103 function removeStyleSheet(tabId, frameId, styleSheet)
93 { 104 {
94 if (!styleSheetRemovalSupported) 105 if (!styleSheetRemovalSupported)
95 return; 106 return;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 response.inlineEmulated = true; 190 response.inlineEmulated = true;
180 191
181 return response; 192 return response;
182 }); 193 });
183 194
184 port.on("elemhide.injectSelectors", (message, sender) => 195 port.on("elemhide.injectSelectors", (message, sender) =>
185 { 196 {
186 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, 197 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors,
187 message.groupName); 198 message.groupName);
188 }); 199 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld