0

I am not able to store value using chrome.storage.sync api i am trying to store tab id of current tab where selectthistab button is pressed from popup.html

this is my manifest.json

 {
    "name": "Reload 4 U",
    "version": "0.1",
    "description": "Reload tab for you!",
    "permissions": ["activeTab","declarativeContent","storage","tabs","alarms"],
    "background": {
        "scripts": ["background.js"],
        "persistent": false
    },
    "page_action": {
      "default_popup": "popup.html"
    },
    "options_page": "options.html",
    "icons": {
      "16": "images/get_started16.png",
      "32": "images/get_started32.png",
      "48": "images/get_started48.png",
      "128": "images/get_started128.png"
    },
    "manifest_version": 2
  }

this is my popup.html

    <!DOCTYPE html>
  <html>
    <head>
      <style>
        button {

        }
      </style>
    </head>
    <body>
      <div>
        <button id="selectThisTab">Select This tab</button>
      </div>
      <script src="popup.js"></script>
    </body>
  </html>

this is my popup.js

    let selectTab = document.getElementById('selectThisTab');

selectTab.onclick = function(element){
    function setTabId(tabs) {
        var currentTab = tabs[0];
        chrome.storage.sync.set({selectedTab: currentTab.id});
    }
var query = { active: true, currentWindow: true };
    chrome.tabs.query(query, setTabId);
    chrome.alarms.create('reloadTabAlarm', {delayInMinutes: 0.1, periodInMinutes: 0.2});
    var tabId = undefined;
     chrome.storage.sync.get('selectedTab',function (data) {
        tabId =  data.selectedTab;
    });
    alert("tab stored "+tabId);
};

this is my background.js

    chrome.runtime.onInstalled.addListener(function() {
    function reloadTab(){
      console.log(chrome.storage.sync.get('selectedTab',function (data) {
        return data.selectedTab;
    }));
    }
    chrome.alarms.onAlarm.addListener(function(alarm) {
        reloadTab();
    });
});

i am not able to store any data for my chrome extension i am trying to store tab id in storage i have storage mentioned in manifest.json but still its not working please help.

Akshay K H
  • 147
  • 1
  • 14

0 Answers0