function handle_header(req) { // Headers // let x = req.requestHeaders; // if (!x) { x = new Headers() // } x.append("og", old) console.log(x) // appending header of the original url so that relative urls can be built into // absolute urls // TODO This doesn't work yet return { requestHeaders: x, } } let old = "" function url_redirect (req) { let url = new URL(req.url); let path = url.pathname; let domain = url.hostname; let b64 = btoa(path) if (!req.url.startsWith("http://localhost")) { old = req.url // console.debug(`Loading: ${req.url} || ${b64}`); return { redirectUrl: `http://localhost:4433/s3/${domain}/${b64}` } } } browser.webRequest.onBeforeSendHeaders.addListener( handle_header, { urls: [""] }, ["blocking", "requestHeaders"] ); browser.webRequest.onBeforeRequest.addListener( url_redirect, { urls: [""] }, ["blocking"] )