'localStorage is not defined in background.js

I am trying to get and set in my extension using background.js but whenever I run the extension I get the error saying that referenceError: localStorage is not defined.

whereas if I use it in my App.js , it is getting and setting in the local storage.

Note: I am using manifest v3

chrome.cookies.get(
      { url: "https://www.xxxx.com/", name: "abc" },
      async (cookie) => {
        const cookieValue: any = cookie?.value;
        oldJwtToken = localStorage.getItem("abc");
        console.log(cookieValue);
        console.log(oldJwtToken);
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source