title: Chrome Extension: Extension context invalidated when getting URL
body: <p>I'm retrieving some images from one of my chrome extension folders to the website DOM and everytime I reload the extension I'm getting a 'Extension Context Invalidated' error. Same thing happens when I do a 'chrome.storage.local.set'.</p>
  <p>Doing some research I have realized that this error has to do with the facts well explained <a href="https://stackoverflow.com/a/55336841/2396605">on this answer</a> but since I'm not messaging between my content script and the background.js I wonder why this happens.</p>
  <p>This is the part of my script (injected via chrome.tabs.executeScript in the popup.js) where I'm getting the error, I'm basically injecting images from one of my extension folders to the website DOM:</p>
  <pre><code>  for (let k = 0; k &lt; incomingChatTags.length; k++) {
      let normalHolderTag = $(incomingChatTags[k]).text().toLowerCase();
      switch (normalHolderTag) {
        case &quot;vip&quot;:
          $(incomingChatTags[k]).addClass(&quot;ce-vip&quot;);
          priorityVal += 300;
          break;
        case &quot;rg&quot;:
          $(incomingChatTags[k]).addClass(&quot;ce-rg&quot;);
          priorityVal += 240;
          break;
        case &quot;accountclosure&quot;:
          $(incomingChatTags[k]).addClass(&quot;ce-accountclosure&quot;);
          priorityVal += 200;
          break;
        case &quot;21com&quot;:
          let logo21 = chrome.extension.getURL(&quot;/images/21_thumb.png&quot;);
          $(incomingChatTags[k]).html('&lt;img src=&quot;' + logo21 + '&quot; /&gt;');
          $(incomingChatTags[k]).addClass(&quot;ce-tag-logo&quot;);
          break;
        case &quot;caxino&quot;:
          //the console shows the error here and not before....¿why? 
          let logoCaxino = chrome.extension.getURL(
            &quot;/images/caxino_thumb.png&quot;
          );
          $(incomingChatTags[k]).html('&lt;img src=&quot;' + logoCaxino + '&quot; /&gt;');
          $(incomingChatTags[k]).addClass(&quot;ce-tag-logo&quot;);
          break;
        case &quot;justspin&quot;:
          let logoJustSpin = chrome.extension.getURL(
            &quot;/images/wildz_thumb.png&quot;
          );
          $(incomingChatTags[k]).html('&lt;img src=&quot;' + logoJustSpin + '&quot; /&gt;');
          $(incomingChatTags[k]).addClass(&quot;ce-tag-logo&quot;);
          break;
        case &quot;neonvegas&quot;:
          let logoNeonVegas = chrome.extension.getURL(
            &quot;/images/neonVegas_thumb.jpg&quot;
          );
          $(incomingChatTags[k]).html('&lt;img src=&quot;' + logoNeonVegas + '&quot; /&gt;');
          $(incomingChatTags[k]).addClass(&quot;ce-tag-logo&quot;);
          break;
        case &quot;nitrocasino&quot;:
          let logoNitroCasino = chrome.extension.getURL(
            &quot;/images/nitroCasino_thumb.jpg&quot;
          );
          $(incomingChatTags[k]).html(
            '&lt;img src=&quot;' + logoNitroCasino + '&quot; /&gt;'
          );
          $(incomingChatTags[k]).addClass(&quot;ce-tag-logo&quot;);
          break;
        case &quot;snabbis&quot;:
          let logoSnabbis = chrome.extension.getURL(
            &quot;/images/snabbis_thumb.png&quot;
          );
          $(incomingChatTags[k]).html('&lt;img src=&quot;' + logoSnabbis + '&quot; /&gt;');
          $(incomingChatTags[k]).addClass(&quot;ce-tag-logo&quot;);
          break;
        case &quot;sb.bet&quot;:
          let logoSB = chrome.extension.getURL(&quot;/images/sb_thumb.png&quot;);
          $(incomingChatTags[k]).html('&lt;img src=&quot;' + logoSB + '&quot; /&gt;');
          $(incomingChatTags[k]).addClass(&quot;ce-tag-logo&quot;);
          break;
        case &quot;wildz&quot;:
          let logoWildz = chrome.extension.getURL(&quot;/images/wildz_thumb.png&quot;);
          $(incomingChatTags[k]).html('&lt;img src=&quot;' + logoWildz + '&quot; /&gt;');
          $(incomingChatTags[k]).addClass(&quot;ce-tag-logo&quot;);
          break;
        case &quot;wishmaker&quot;:
          let logoWishMaker = chrome.extension.getURL(
            &quot;/images/wishmaker_thumb.png&quot;
          );
          $(incomingChatTags[k]).html('&lt;img src=&quot;' + logoWishMaker + '&quot; /&gt;');
          $(incomingChatTags[k]).addClass(&quot;ce-tag-logo&quot;);
          break;
      }
      $(incomingChat).attr(&quot;data-priority&quot;, priorityVal);
      $(incomingChat).find(&quot;.numbers_cell&quot;).text(priorityVal);
    }
  </code></pre>