in src/js/relay.firefox.com/get_profile_data.js [57:98]
async function apiRequest(url, method = "GET", body = null, opts=null) {
const cookieString =
typeof document.cookie === "string" ? document.cookie : "";
const cookieStringArray = cookieString
.split(";")
.map((individualCookieString) => individualCookieString.split("="))
.map(([cookieKey, cookieValue]) => [
cookieKey.trim(),
cookieValue.trim(),
]);
const [_csrfCookieKey, csrfCookieValue] = cookieStringArray.find(
([cookieKey, _cookieValue]) => cookieKey === "csrftoken"
);
browser.storage.local.set({ csrfCookieValue: csrfCookieValue });
const headers = new Headers();
headers.set("X-CSRFToken", csrfCookieValue);
headers.set("Content-Type", "application/json");
headers.set("Accept", "application/json");
if (opts && opts.auth) {
const apiToken = await browser.storage.local.get("apiToken");
headers.set("Authorization", `Token ${apiToken.apiToken}`);
}
const response = await fetch(url, {
mode: "same-origin",
method,
headers: headers,
body,
});
const answer = await response.json();
return answer;
}