Get Checksum of file from webRequest
<p>I am writing a Google Chrome extension that contains a whitelist of SHA256 checksums for javascript files. Only files within this whitelist are supposed to execute, all others should be blocked.</p>

<p>Currently, i use this <strong>inefficient but working code</strong> for getting a checksum and blocking the request.</p>

<pre><code>chrome.webRequest.onHeadersReceived.addListener(
    function(details) {
        if(details.type == "script")
        {
            return getURL(details.url, false, function(data) {
                var content = sha256(data);

                if( hashList.indexOf(content) == -1 )
                {
                    console.error(details.url+" not in whitelist");
                    return {cancel: true};
                }
            });
        }
    }, {
        urls: ["&lt;all_urls&gt;"],
        types: ["main_frame","script"]
    }, ["blocking", "responseHeaders"]
);
</code></pre>

<p>The problems with this code:</p>

<ul>
<li>It is quite inefficient as this requires downloading every file twice.</li>
<li>It has to be running synchronously to stop the files before arriving at the client. This makes the delay even bigger.</li>
</ul>

<p>I want to know / ask whether there are ways to circumvent those issues by accessing the source file without downloading it twice (didnt find anything in the <a href="https://developer.chrome.com/extensions/webRequest" rel="nofollow">documentation</a>) or at least increase the performance by any other means.</p>