Skip to content

Instantly share code, notes, and snippets.

View Pytness's full-sized avatar
👾

Fernando Vega Catalán Pytness

👾
  • FCC
  • Madrid, Spain
View GitHub Profile
@josephrocca
josephrocca / background.js
Last active July 27, 2023 04:37
Chrome extension to force-enable CORS based on request's *source* url (i.e. the url of the browser tab) rather than the target url
// Notes: we need the `sourceTabUrl &&` before the URL check because chromebooks make weird requests that don't come from "real" tabs.
let accessHeaders = new Map();
let tabIdToUrlMap = new Map();
let requestListener = function (details) {
const accessControlRequestHeader = details.requestHeaders.find(elem => elem.name.toLowerCase() === "access-control-request-headers");
if(accessControlRequestHeader) {
accessHeaders.set(details.requestId, accessControlRequestHeader.value);
}