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

Side by Side Diff: inject.preload.js

Issue 29890555: Issue 6914 - Wrap window.frameElement in try catch to silence Microsoft Edge exception (Closed)
Patch Set: Created Sept. 24, 2018, 11:21 a.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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 350
351 if ("RTCPeerConnection" in window) 351 if ("RTCPeerConnection" in window)
352 window.RTCPeerConnection = boundWrappedRTCPeerConnection; 352 window.RTCPeerConnection = boundWrappedRTCPeerConnection;
353 if ("webkitRTCPeerConnection" in window) 353 if ("webkitRTCPeerConnection" in window)
354 window.webkitRTCPeerConnection = boundWrappedRTCPeerConnection; 354 window.webkitRTCPeerConnection = boundWrappedRTCPeerConnection;
355 } 355 }
356 } 356 }
357 357
358 if (document instanceof HTMLDocument) 358 if (document instanceof HTMLDocument)
359 { 359 {
360 let sandbox = window.frameElement && 360 let sandbox;
361 window.frameElement.getAttribute("sandbox"); 361
362 // We have to wrap the following code in a try catch
363 // because of this Microsoft Edge bug:
364 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/190829 80/
365 try
366 {
367 sandbox = window.frameElement &&
368 window.frameElement.getAttribute("sandbox");
369 }
370 catch (e) {}
362 371
363 if (typeof sandbox != "string" || /(^|\s)allow-scripts(\s|$)/i.test(sandbox)) 372 if (typeof sandbox != "string" || /(^|\s)allow-scripts(\s|$)/i.test(sandbox))
364 { 373 {
365 let script = document.createElement("script"); 374 let script = document.createElement("script");
366 let code = "(" + injected + ")('" + randomEventName + "');"; 375 let code = "(" + injected + ")('" + randomEventName + "');";
367 376
368 script.type = "application/javascript"; 377 script.type = "application/javascript";
369 script.async = false; 378 script.async = false;
370 379
371 // Firefox 58 only bypasses site CSPs when assigning to 'src', 380 // Firefox 58 only bypasses site CSPs when assigning to 'src',
372 // while Chrome 67 only bypasses site CSPs when using 'textContent'. 381 // while Chrome 67 only bypasses site CSPs when using 'textContent'.
373 if (browser.runtime.getURL("").startsWith("chrome-extension://")) 382 if (browser.runtime.getURL("").startsWith("chrome-extension://"))
374 { 383 {
375 script.textContent = code; 384 script.textContent = code;
376 document.documentElement.appendChild(script); 385 document.documentElement.appendChild(script);
377 } 386 }
378 else 387 else
379 { 388 {
380 let url = URL.createObjectURL(new Blob([code])); 389 let url = URL.createObjectURL(new Blob([code]));
381 script.src = url; 390 script.src = url;
382 document.documentElement.appendChild(script); 391 document.documentElement.appendChild(script);
383 URL.revokeObjectURL(url); 392 URL.revokeObjectURL(url);
384 } 393 }
385 394
386 document.documentElement.removeChild(script); 395 document.documentElement.removeChild(script);
387 } 396 }
388 } 397 }
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