Jomol MJ
Jomol MJ

Reputation: 691

Chrome extension background.js file reload

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'"
}

Upvotes: 2

Views: 3348

Answers (1)

Joe
Joe

Reputation: 2540

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);
       });
    }
})

Upvotes: 1

Related Questions