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: Update comment Created March 13, 2018, 10:06 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 function createStyleSheet(selectors) 64 function createStyleSheet(selectors)
65 { 65 {
66 return Array.from(createRules(selectors)).join("\n"); 66 return Array.from(createRules(selectors)).join("\n");
67 } 67 }
68 68
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 let promise = 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
81 // See error handling notes in the catch block.
82 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.
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 // For other errors, we simply return false to indicate failure.
93 //
94 // One common error that occurs frequently is when a frame is not found
95 // (e.g. "Error: No frame with id 574 in tab 266"), which can happen when
96 // the code in the parent document has removed the frame before the
97 // background page has had a chance to respond to the content script's
98 // "elemhide.getSelectors" message. We simply ignore such errors, because
99 // otherwise they show up in the log too often and make debugging
100 // difficult.
101 //
102 // Also note that the missing frame error is thrown synchronously on
103 // Firefox, while on Chromium it is an asychronous promise rejection. In
104 // 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
105 // explicitly ignore the error.
86 return false; 106 return false;
87 } 107 }
88 108
89 return true; 109 return true;
90 } 110 }
91 111
92 function removeStyleSheet(tabId, frameId, styleSheet) 112 function removeStyleSheet(tabId, frameId, styleSheet)
93 { 113 {
94 if (!styleSheetRemovalSupported) 114 if (!styleSheetRemovalSupported)
95 return; 115 return;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 response.inlineEmulated = true; 199 response.inlineEmulated = true;
180 200
181 return response; 201 return response;
182 }); 202 });
183 203
184 port.on("elemhide.injectSelectors", (message, sender) => 204 port.on("elemhide.injectSelectors", (message, sender) =>
185 { 205 {
186 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, 206 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors,
187 message.groupName); 207 message.groupName);
188 }); 208 });
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