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

Side by Side Diff: lib/contentFiltering.js

Issue 29850574: Issue 6841 - Avoid passing frameId of 0 to tabs.executeScript (Closed)
Patch Set: Created Aug. 8, 2018, 2:49 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 code = compileScript(script, [snippetsLibrarySource]); 173 code = compileScript(script, [snippetsLibrarySource]);
174 174
175 executableCode.set(script, code); 175 executableCode.set(script, code);
176 return code; 176 return code;
177 } 177 }
178 178
179 function executeScript(script, tabId, frameId) 179 function executeScript(script, tabId, frameId)
180 { 180 {
181 try 181 try
182 { 182 {
183 browser.tabs.executeScript(tabId, { 183 let details = {
184 code: getExecutableCode(script), 184 code: getExecutableCode(script),
185 frameId,
186 matchAboutBlank: true, 185 matchAboutBlank: true,
187 runAt: "document_start" 186 runAt: "document_start"
188 }) 187 };
188
189 // Chrome <50 throws an exception if chrome.tabs.executeScript is called
190 // with a frameId of 0.
191 if (frameId != 0)
192 details.frameId = frameId;
193
194 browser.tabs.executeScript(tabId, details)
189 .catch(error => 195 .catch(error =>
190 { 196 {
191 // Sometimes a frame is added and removed very quickly, in such cases we 197 // Sometimes a frame is added and removed very quickly, in such cases we
192 // simply ignore the error. 198 // simply ignore the error.
193 if (error.message == "The frame was removed.") 199 if (error.message == "The frame was removed.")
194 return; 200 return;
195 201
196 // Sometimes the frame in question is just not found. We don't know why 202 // Sometimes the frame in question is just not found. We don't know why
197 // this is exactly, but we simply ignore the error. 203 // this is exactly, but we simply ignore the error.
198 if (/^No frame with id \d+ in tab \d+\.$/.test(error.message)) 204 if (/^No frame with id \d+ in tab \d+\.$/.test(error.message))
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, 272 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors,
267 message.groupName, message.appendOnly); 273 message.groupName, message.appendOnly);
268 }); 274 });
269 275
270 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"}) 276 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"})
271 .then(response => response.ok ? response.text() : "") 277 .then(response => response.ok ? response.text() : "")
272 .then(text => 278 .then(text =>
273 { 279 {
274 snippetsLibrarySource = text; 280 snippetsLibrarySource = text;
275 }); 281 });
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