title: Background script only for specific domain in Chrome extension
body: <p>I would like to know how to run the background script of a Chrome extension for only specific/specified domain/s please?</p>
  
  <p>For example, if an extension is meant to run only on pages of Google.com, so there is no reason to keep the background script running on any other domains.  </p>
  
  <p>In my manifest file I have set "matches" but I can still see the background script running on every domain and tab.</p>
  
  <pre><code>...
  
  "background": {
      "matches": [
          "*://*.google.com/*"
      ],
      "scripts": ["scripts/background.js"],
      "persistent": false
  },
  
  "content_scripts": [
      {
          "matches": [
              "*://*.google.com/*"
          ],
          "css": ["styles/default.css"],
          "js": ["scripts/jquery.js", "scripts/default.js"]
      }
  ],
  
  "permissions": [
      "storage",
      "declarativeContent",
      "tabs"
  ],
  
  ...
  </code></pre>
  
  <p><strong>Edit</strong><br>
  To add more info that will help understand my goal:<br>
  I have a content script and a popup, the popup is being used as a remote control with options to choose from and play with, that will eventually effects the page.<br>
  When changing an option in the popup, it sends it's value to the background/event script, there it being temporary saved in a variable, and then being sent to the content script, where it actually being executing and show up on the page to the user.<br>
  And I want that only when the user leaves the specific domain, the background/event script will save the settings to storage, so by that there will be only a single storage saving task and NOT each time the user is changing a setting in the popup.<br>
  After the settings got saved to storage and the user left, I want nothing to run it the background anymore please.</p>