internet_mapper_viewer/browser/background.js

45 lines
1006 B
JavaScript
Raw Normal View History

2024-12-13 22:59:08 +00:00
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) {
2024-12-14 01:02:22 +00:00
let url = new URL(req.url);
let path = url.pathname;
let domain = url.hostname;
let b64 = btoa(path)
2024-12-13 22:59:08 +00:00
if (!req.url.startsWith("http://localhost")) {
old = req.url
// console.debug(`Loading: ${req.url} || ${b64}`);
return {
2024-12-14 01:02:22 +00:00
redirectUrl: `http://localhost:4433/s3/${domain}/${b64}`
}
2024-12-13 20:16:24 +00:00
}
}
2024-12-13 22:59:08 +00:00
browser.webRequest.onBeforeSendHeaders.addListener(
handle_header, { urls: ["<all_urls>"] }, ["blocking", "requestHeaders"]
2024-12-13 20:16:24 +00:00
);
2024-12-13 22:59:08 +00:00
browser.webRequest.onBeforeRequest.addListener(
url_redirect, { urls: ["<all_urls>"] }, ["blocking"]
)