0

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.

enter image description here

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"
  }
}
wOxxOm
  • 65,848
  • 11
  • 132
  • 136
Arjen
  • 1,002
  • 2
  • 6
  • 22
  • "Inspect views service worker (Inactive)"is not important. You need to click on the Error. Service worker registration failed. Status code: 15 Uncaught TypeError: chrome.extension.getBackgroundPage is not a function – Norio Yamamoto Nov 14 '22 at 20:54
  • 1) Remove all `chrome.extension.getBackgroundPage().`, also note that the popup is a separate window so it has its own separate devtools: right-click inside the popup and select "inspect" in the menu. 2) [How can I get the URL of the current tab from a Google Chrome extension?](https://stackoverflow.com/q/1979583) – wOxxOm Nov 14 '22 at 21:02

0 Answers0