1

EDIT

My chrome extension calling an api service in the background.js file and i can get the data. But after closing the browser window, i cant get the data from the api service in background.js file. It showing null value. When go to the chrome://extensions/ and reload the extension I can get the data.

When close the browser window, the data fetched is being reset and when open the browser, data not fetching. Data can be fetched from the api only after reloading the extension.

Why happening so. Does any one have an idea about this?

This is my manifest.json file

{
  "manifest_version": 2,
  "icons": {
    "16": "images/icon16.png",
    "32": "images/icon32.png",
    "48": "images/icon48.png",
    "128": "images/icon128.png"
  },
  "name": "Test",
  "short_name": "Test",
  "description": "Test",
  "version": "3.0.0",
  "background": {
    "scripts": [
      "build/background-bundle.js"
    ]
  },
  "browser_action": {
    "default_popup": "popup.html"
  },
  "permissions": [
    "tabs",
    "cookies",
    "storage",
    "activeTab",
    "http://*/",
    "https://*/"
  ],
  "content_scripts": [{
    "matches": [
      "<all_urls>"
    ],
    "js": [
      "build/content-bundle.js"
    ],
    "run_at": "document_end"
  }], 
  "options_ui": {    
    "page": "options.html",
    "chrome_style": true 
  },
  "content_security_policy": "script-src 'self' https://www.google-analytics.com/analytics.js https://api.algorithmia.com/v1/algo/algo://nlp/SummarizeURL/0.1.1; object-src 'self'"
}
Jomol MJ
  • 671
  • 1
  • 6
  • 23
  • what does "next version" mean above? – Joe Nov 18 '16 at 04:58
  • and where in the above are you "passing some additional data based on the user login id' – Joe Nov 18 '16 at 05:03
  • Next version means - the next version of extension. https://sample-api-call will fetch the data based on the user cookie. – Jomol MJ Nov 18 '16 at 05:23
  • sample-api-call is being fetched in the background script. Chrome extension background scripts don't share cookies with the browser tabs, so I don't think that part will work. See http://stackoverflow.com/questions/24923344/does-chrome-extension-has-its-own-document-cookie for more info – Joe Nov 18 '16 at 06:04

1 Answers1

1

You can't reload the background file based on anything other than reopening the browser or reloading the extension manually. What you should instead do is have a content script tell background.js to run getTaxonomyList again when the user log in happens.

background.js:

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    if (request.userLoggedIn) {
       getTaxonomyList().done(function(list) {
          sendResponse(list);
       });
    }
})
Joe
  • 2,500
  • 1
  • 14
  • 12