Search code examples
google-chromegoogle-chrome-extensionchrome-extension-manifest-v3

Chrome storage API not working in MV3 for Chrome extension


I'm having troubles getting chrome storage API to work in MV3. I've tried this so far and even in the service worker console it returns an undefined result

chrome.storage.local.set({ 'test': 'test' }, function() {
        chrome.storage.local.get('test', function(result) {
            console.log('Value currently is ' + result);
        });
    });

Here is my manifest I'm not sure if that's an issue

{
    "manifest_version": 3,
    "name": "NAME",
    "description": "Description",
    "version": "0.0.3",
    "background": {
        "service_worker": "background.js"
    },
    "content_security_policy": {
        "extension_pages": "script-src 'self'; object-src 'self'"
     }, 
    "action": {
        "default_icon": {             
          "16": "favicon.ico"         
        },
        "default_title": "Outboundly",  
        "default_popup": "index.html" 
    },  
    "permissions": [
        "storage",
        "scripting",
        "activeTab",
        "tabs",     
        "unlimitedStorage"
    ],
    "host_permissions": ["<all_urls>"]  
}

I've also tried it in the content script and within the popup context as well.


Solution

  • I'm not sure why but I changed the position of the permissions around in the manifest, and that seemed to have fixed things. Possibly a bug.

    {
        "manifest_version": 3,
        "name": "NAME",
        "description": "Description",
        "version": "0.0.3",
        "background": {
            "service_worker": "background.js"
        },
        "content_security_policy": {
            "extension_pages": "script-src 'self'; object-src 'self'"
         },
        "permissions": [
            "storage",
            "scripting",
            "activeTab",
            "tabs",     
            "unlimitedStorage"
        ],
        "host_permissions": ["<all_urls>"] 
        "action": {
            "default_icon": {             
              "16": "favicon.ico"         
            },
            "default_title": "Outboundly",  
            "default_popup": "index.html" 
        }  
    }