MCPcopy Create free account
hub / github.com/Tampermonkey/tampermonkey / TM_xmlhttpRequest

Function TM_xmlhttpRequest

src/environment.js:693–747  ·  view source on GitHub ↗
(details)

Source from the content-addressed store, hash-verified

691};
692
693var TM_xmlhttpRequest = function(details) {
694 var forget = false;
695
696 var callit = function(fn, arg) {
697 var run = function() {
698 fn(arg);
699 };
700 if (fn && !forget) window.setTimeout(run, 1);
701 };
702
703 var xmlhttp2 = !!details.responseType;
704 if (/* TMwin.use.safeContext */ xmlhttp2) {
705 var load = function(r) {
706 callit(details["onload"], r);
707 };
708 var readystatechange = function(r) {
709 callit(details["onreadystatechange"], r);
710 };
711 var error = function(r) {
712 callit(details["onerror"], r);
713 }
714
715 chromeEmu.xmlHttpRequest(details, load, readystatechange, error);
716 } else {
717 var port = chromeEmu.extension.connect('xhr_' + TM_context_id);
718 port.postMessage({ method: "xhr", details: details, id: TM_context_id });
719
720 var plist = function(response) {
721 try {
722 if (response.success) {
723 if (details["onload"]) {
724 if (response.data.responseXML) response.data.responseXML = unescape(response.data.responseXML);
725 callit(details["onload"], response.data);
726 }
727 } else if (response.change) {
728 if (details["onreadystatechange"]) {
729 callit(details["onreadystatechange"], response.data);
730 }
731 } else {
732 if (details["onerror"]) {
733 callit(details["onerror"], response.data);
734 }
735 }
736 } catch (e) {
737 console.log("env: Error: TM_xmlhttpRequest - " + e.message + "\n" + JSON.stringify(details));
738 }
739 };
740
741 port.onMessage.addListener(plist);
742 var omsg = function(response) { console.log("env: onDisconnect! :)")};
743 if (V) port.onDisconnect.addListener(omsg);
744 }
745
746 return { abort: function() { forget = true; } };
747}
748
749var TM_getTab = function(cb) {
750 chromeEmu.extension.sendMessage({method: "getTab", id: TM_context_id}, function(response) {

Callers 1

GM_EMUFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…