| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 Loading... | |
| 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 .catch(() => {}); | 80 |
|
Sebastian Noack
2018/03/12 22:41:25
To clarify, so the catch-block below is essentiall
Manish Jethani
2018/03/13 06:09:47
On both Firefox and Chrome 65 the error for "cssOr
Sebastian Noack
2018/03/13 15:38:45
I see. Perhaps add some comments here, clarifying
Manish Jethani
2018/03/13 17:14:20
Done.
| |
| 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.
| |
| 81 } | 83 } |
| 82 catch (error) | 84 catch (error) |
| 83 { | 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. | |
| 84 if (/\bcssOrigin\b/.test(error.message)) | 89 if (/\bcssOrigin\b/.test(error.message)) |
| 85 userStyleSheetsSupported = false; | 90 userStyleSheetsSupported = false; |
| 86 | 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. | |
| 87 return false; | 106 return false; |
| 88 } | 107 } |
| 89 | 108 |
| 90 return true; | 109 return true; |
| 91 } | 110 } |
| 92 | 111 |
| 93 function removeStyleSheet(tabId, frameId, styleSheet) | 112 function removeStyleSheet(tabId, frameId, styleSheet) |
| 94 { | 113 { |
| 95 if (!styleSheetRemovalSupported) | 114 if (!styleSheetRemovalSupported) |
| 96 return; | 115 return; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 response.inlineEmulated = true; | 199 response.inlineEmulated = true; |
| 181 | 200 |
| 182 return response; | 201 return response; |
| 183 }); | 202 }); |
| 184 | 203 |
| 185 port.on("elemhide.injectSelectors", (message, sender) => | 204 port.on("elemhide.injectSelectors", (message, sender) => |
| 186 { | 205 { |
| 187 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, | 206 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, |
| 188 message.groupName); | 207 message.groupName); |
| 189 }); | 208 }); |
| LEFT | RIGHT |