'How can I make HTTP request wait before continuing

I'm developing an extension for Google Chrome and I'm monitoring HTTP requests. In the event handler for chrome.webRequest.onHeadersReceived I'm trying to make a delay. It cannot wait asynchronously (unlike WebExtensions in Firefox) and it doesn't support something like Thread.Sleep or CriticalSection or ResetEvent or anything. The only solution that I see is spin waiting which is a very bad choice. Even synchronous XMLHTTPRequest is deprecated and doesn't work.

var headersReceived = function (e) {
    /// ?????? some method to delay synchronously
    return {cancel: false};
};

chrome.webRequest.onHeadersReceived.addListener(headersReceived,
                                                {urls: ["*://*/*"]},
                                                ["blocking", "responseHeaders"]);


Solution 1:[1]

You can try and reference to this plugin: network-spinner-devtool it is a browser devtools extension, with capacity of URL level configuration and control, to allow introducing delay before sending http request or after receiving response(support in firefox only).

it supports both Chrome and Firefox browser

Can install from Chrome web store as well Chrome DevTools

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 coder_ll