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

Unified Diff: lib/cssInjection.js

Issue 29720585: Noissue - Explicitly ignore asynchronous errors from tabs.insertCSS (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Update comment Created March 13, 2018, 10:06 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/cssInjection.js
===================================================================
--- a/lib/cssInjection.js
+++ b/lib/cssInjection.js
@@ -65,29 +65,49 @@
{
return Array.from(createRules(selectors)).join("\n");
}
function addStyleSheet(tabId, frameId, styleSheet)
{
try
{
- browser.tabs.insertCSS(tabId, {
+ 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(() => {});
Manish Jethani 2018/03/13 22:08:38 I actually find it a lot cleaner to have a promise
Sebastian Noack 2018/03/13 23:02:21 Well, now where you you just refer to the other co
Manish Jethani 2018/03/13 23:08:30 Ack, but I do prefer this if you don't mind.
}
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))
userStyleSheetsSupported = false;
+ // 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
+ // "elemhide.getSelectors" message. We simply ignore such errors, because
+ // otherwise they show up in the log too often and make debugging
+ // difficult.
+ //
+ // Also note that the missing frame error is thrown synchronously on
+ // Firefox, while on Chromium it is an asychronous promise rejection. In
+ // the latter case, we cannot indicate failure to the caller, but we still
Sebastian Noack 2018/03/13 23:02:21 Well, we could signal failure, by returning a prom
Manish Jethani 2018/03/13 23:08:30 That's not necessary at least for the case of the
Manish Jethani 2018/03/13 23:10:30 Also note that returning a promise from here would
+ // explicitly ignore the error.
return false;
}
return true;
}
function removeStyleSheet(tabId, frameId, styleSheet)
{
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld