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, 5:41 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 on Chromium are asynchronous promise rejections
81 // (e.g. "Error: No frame with id 574 in tab 266"). We explicitly ignore
82 // these, because otherwise they show up in the log too often and make
83 // debugging difficult.
84 .catch(() => {});
80 } 85 }
81 catch (error) 86 catch (error)
82 { 87 {
88 // If the error is about the "cssOrigin" option, this is an older version
89 // of Chromium (65 and below) or Firefox (52 and below) that does not
90 // support user style sheets.
83 if (/\bcssOrigin\b/.test(error.message)) 91 if (/\bcssOrigin\b/.test(error.message))
84 userStyleSheetsSupported = false; 92 userStyleSheetsSupported = false;
85 93
94 // Sometimes a frame gets removed from the document between the time the
95 // content script sends the "elemhide.getSelectors" message and the time
96 // the background page tries to inject a style sheet, which causes
97 // tabs.insertCSS to throw a frame-not-found error. We must handle any such
98 // errors.
Sebastian Noack 2018/03/13 18:40:58 This is only the case on Firefox, while Chromium g
Manish Jethani 2018/03/13 22:08:38 Done.
86 return false; 99 return false;
87 } 100 }
88 101
89 return true; 102 return true;
90 } 103 }
91 104
92 function removeStyleSheet(tabId, frameId, styleSheet) 105 function removeStyleSheet(tabId, frameId, styleSheet)
93 { 106 {
94 if (!styleSheetRemovalSupported) 107 if (!styleSheetRemovalSupported)
95 return; 108 return;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 response.inlineEmulated = true; 192 response.inlineEmulated = true;
180 193
181 return response; 194 return response;
182 }); 195 });
183 196
184 port.on("elemhide.injectSelectors", (message, sender) => 197 port.on("elemhide.injectSelectors", (message, sender) =>
185 { 198 {
186 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, 199 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors,
187 message.groupName); 200 message.groupName);
188 }); 201 });
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