Last active
October 4, 2021 14:24
-
-
Save wesinator/bfdd83ec8472de1336f423d3c7d073bb to your computer and use it in GitHub Desktop.
Snippet for chrome extension to open tab, attempting to work around Chrome 94 CSP bug. Requires `debugger` permission in manifest. https://bugs.chromium.org/p/chromium/issues/detail?id=1245803
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chrome.tabs.create({ | |
url: tabUrl, | |
index: tab.index + 1, | |
active: false | |
}, | |
function (tab) { | |
const m = navigator.userAgent.match(/Chrome\/([\d]+)/); | |
/* attempt to workaround issue introduced in Chrome 94+ | |
https://bugs.chromium.org/p/chromium/issues/detail?id=1245803 | |
based on https://github.com/webrecorder/archiveweb.page/pull/55 | |
*/ | |
if (Number(m[1]) >= 94) { | |
chrome.debugger.attach({tabId: tab.id}, "1.3"); | |
chrome.debugger.sendCommand( | |
{tabId: tab.id}, | |
"Page.setBypassCSP", | |
{enabled: true}, | |
null | |
); | |
chrome.tabs.reload(tab.id); | |
chrome.debugger.detach({tabId: tab.id}); | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment