title: Chrome extension (message from background to other js) : Could not establish connection. Receiving end does not exist
body: <p>Since background.js is a service worker, I can't use DOM function or localstorage. I'm trying to find a way around by using messages to execute JS outside background.js but with simple message passing, I get the error message: Could not establish connection. Receiving end does not exist.</p>
  <p>In background.js I have:</p>
  <pre><code>chrome.runtime.sendMessage({ data: [action] }, function (response) 
      {
          console.log('sending message');
      });
  </code></pre>
  <p>In popup.js I have:</p>
  <pre><code>chrome.runtime.onMessage.addListener((message, sender, reply) =&gt; 
  {
      console.log('message received');
  }); 
  </code></pre>
  <p>What I'm trying to achieve:</p>
  <ol>
  <li>Update translations, error messages, ... once a day. In that case I create an alarm in background.js that downloads JSON containing the metadata but I then need to store it locally but that doesn't work with background.js</li>
  <li>Create a tab, download the source code and parse it. I could do this in background.js in manifest v2 but I had to move those functions to popup.js but that's annoying because popup.js can easily be interrupted.</li>
  </ol>
  <p>How could I use background.js to create recurring tasks in the background and send some content to other scripts to compensate for what background.js cannot do? I guess popup.js is not always active or always listening, that's probably why I get this error message.</p>
  <p>I thought of using this:</p>
  <pre><code>chrome.scripting.executeScript( 
  {
  target: {tabId: tab.id, allFrames: true},
  files: ['myscript.js'],
  }
  </code></pre>
  <p>but I need a target that I don't have for my use cases.</p>
  <p>thanks</p>