Search code examples
google-chrome-extensionlocal-storagechrome-extension-manifest-v3

Access to Local Storage of current page using Chrome Extension Manifest Version 3


I'm migrating from manifest version 2 to version 3 and one of the functions I used to have to access the local storage of the current page was using this script:

chrome.tabs.executeScript({code:'JSON.stringify(localStorage)'},function(result) {});

From the page these are the values I need to access:

enter image description here

What would be the recommendation in order to pull all keys?


Solution

  • I was able to access to the values using this scrip on the popup.js file.

    function getLocalStorage(){
         return  JSON.stringify(localStorage);
     }
    
    chrome.scripting.executeScript({
    target: { tabId: currentTab}, // you can get the Tab id using chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {});
        func: getLocalStorage,
    },
    (injectionResults) => {
        console.log('storage response: '+injectionResults[0].result); 
    });
    

    Hope this helps.