I'm trying to force a synchronous repaint. Is this possible?
Unfortunately, the library I am working with sends a long-running synchronous request via XMLHttpRequest.prototype.open(_, _, false)
. I am trying to update the page with a loading indicator before the request is sent by monkey patching XMLHttpRequest.prototype.send
, however, the opacity: 0.7
style is never seen:
const oldSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function(...args) {
document.body.style.opacity = "0.7";
// is there something I can do to force a repaint on this line?
const retVal = oldSend.bind(this)(...args);
document.body.style.opacity = "1";
return retVal;
}
Most of my research suggests refactoring to something asynchronous:
However, I don't have control over the code making the synchronous request.
EDIT: another related post: