Browse Source

Respect `defer` attribute when mirroring

pull/2/head
Deathamns 10 years ago
committed by gorhill
parent
commit
ef30ab4c2d
  1. 11
      src/js/vapi-client.js

11
src/js/vapi-client.js

@ -282,9 +282,20 @@ if (self.chrome) {
e.preventDefault(); e.preventDefault();
details = document.createElement('script'); details = document.createElement('script');
details.textContent = atob(response.slice(response.indexOf(',', 20) + 1)); details.textContent = atob(response.slice(response.indexOf(',', 20) + 1));
if (e.target.hasAttribute('defer') && document.readyState === 'loading') {
var jsOnLoad = function(ev) {
this.removeEventListener(ev.type, jsOnLoad, true);
this.body.removeChild(this.body.appendChild(details));
};
document.addEventListener('DOMContentLoaded', jsOnLoad, true);
}
else {
e.target.parentNode.insertBefore(details, e.target); e.target.parentNode.insertBefore(details, e.target);
details.parentNode.removeChild(details); details.parentNode.removeChild(details);
} }
}
}; };
document.addEventListener('beforeload', onBeforeLoad, true); document.addEventListener('beforeload', onBeforeLoad, true);

Loading…
Cancel
Save