I want a browser extension to read the cookies of a webpage. I want also want the extension only to work on that particular webpage. So i have a button, load cookies and a background.js file:
chrome.extension.getBackgroundPage().console.log("loaded");
function getCookies(domain, name) {
chrome.extension.getBackgroundPage().console.log("loading cookeis");
chrome.cookies.getAll({ url: domain }, function (cookies) {
chrome.extension.getBackgroundPage().console.log(cookies);
});
// return await chrome.cookies.getAll();
}
getCookies(window.location.href, "csrftoken");
document.addEventListener("DOMContentLoaded", function () {
chrome.extension.getBackgroundPage().console.log("loading cookeis");
const loadCookies = document.getElementById("load_cookies");
// onClick's logic below:
loadCookies.addEventListener("click", function () {
getCookies(window.location.href, "x");
});
});
But it does seem like this does not get loaded.
I also get this, which lets me know that the worker is not loaded.
Manifest.json:
{
"manifest_version": 3,
"name": "Management Extension",
"short_name": "Management",
"version": "1",
"description": "A management tool ",
"permissions": ["cookies"],
"background": {
"service_worker": "background.js"
},
"action": {
"default_popup": "index.html"
}
}