xmlhttprequest - Monkeypatch Javascript constructor -



xmlhttprequest - Monkeypatch Javascript constructor -

i've read of other related answers i've been able find, none has worked. essentially, want create source: https://github.com/gildas-lormeau/zip.js/blob/master/webcontent/zip-ext.js

add custom headers the xmlhttprequest on line 93. since httprangereader wrapped in anonymous function, can't monkeypatch directly, , seems alternative monkeypatch xmlhttprequest constructor. need phone call default constructor , phone call setrequestheader() 1 or more times before returning new object.

use alias clone original:

var \u1000setrequestheader = xmlhttprequest.prototype.setrequestheader;

then reference in method override:

xmlhttprequest.prototype.setrequestheader = function httprangeshim(foo,bar, baz) { \u1000setrequestheader.call(this,"custom","1"); \u1000setrequestheader.call(this,"custom","2"); \u1000setrequestheader.call(foo,bar,baz); } (new xmlhttprequest) { setrequestheader(this, "referer","http://www.example.com") }

references

ajax interception javascript override patterns xmlhttprequest specification: setrequestheader capturing javascript console.log? ecmascript strawman: subclassable builtins

javascript xmlhttprequest monkeypatching zip.js

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -