Skip to content

Instantly share code, notes, and snippets.

@wesinator
Last active October 4, 2021 14:24
Show Gist options
  • Save wesinator/bfdd83ec8472de1336f423d3c7d073bb to your computer and use it in GitHub Desktop.
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
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