title: Wait for executeScript to finish
body: <p>I have this script I execute from a Chrome extension</p>
  <pre class="lang-js prettyprint-override"><code>export const getData = () =&gt; {
    chrome.tabs.query({ active: true, currentWindow: true }, tabs =&gt; {
      chrome.tabs.executeScript(
        tabs[0]?.id,
        { code: `document.getElementById('a1').innerHTML;` }, parseData
      );
    });
  };
  
  const parseData = (result: any) =&gt; {
    const obj = new Something();
    // Do complex stuff with this object
    chrome.storage.sync.set(
      {
        id: obj.id,
      }
      );
    console.log('ID from extract', obj.id);
  };
  </code></pre>
  <p>From my background script, I call this function and then call the function that gets the parsed data through chrome storage, so both of these functions take callbacks as arguments.</p>
  <p>I need my first function to finish before executing the other one but it's completely ignoring the <code>await</code>, I'm not sure why and how can I make it wait, if it's even possible</p>
  <p><strong>background script</strong></p>
  <pre class="lang-js prettyprint-override"><code>chrome.runtime.onMessage.addListener(async(request, sender, sendResponse) =&gt; {
      let list = [];
        await getData();
        await getExtractedData((value) =&gt; {
          // Do a lot of stuff with `list`
          console.log('After extract:', value);
        });
    }
  );
  
  </code></pre>
  <p><code>getExtractedData</code> function is in another file:</p>
  <pre class="lang-js prettyprint-override"><code>export const getExtractedData = (callback) =&gt; {
    return chrome.storage.sync.get(
      [
        'id',
      ],
      callback);
  };
  </code></pre>
  <p>It's supposed print this:</p>
  <pre><code>ID from extract 123456
  After extract {id: 123456}
  </code></pre>
  <p>But it's currently doing this:</p>
  <pre><code>After extract {id: 123455}
  ID from extract 123456
  </code></pre>
  <p>(After extract is logging what it extracted in the previous run, but not in the current run)</p>