-
-
Save yashojha87/2abc276c712ab3a20e7c2efcc0623c6b to your computer and use it in GitHub Desktop.
JS: Listen to ajax call and download quickly expiring presigned s3 urls (do not paste twice in the console)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var openOrig = window.XMLHttpRequest.prototype.open, | |
sendOrig = window.XMLHttpRequest.prototype.send, | |
onReadyStateChange; | |
function openReplacement(method, url, async, user, password) { | |
var syncMode = async !== false ? 'async' : 'sync'; | |
console.warn( | |
'Preparing ' + | |
syncMode + | |
' HTTP request : ' + | |
method + | |
' ' + | |
url | |
); | |
this.__url = url; | |
this._windowRef = window; | |
return openOrig.apply(this, arguments); | |
} | |
function sendReplacement(data) { | |
console.warn('Sending HTTP request data : ', data); | |
if(this.onreadystatechange) { | |
this._onreadystatechange = this.onreadystatechange; | |
} | |
this.onreadystatechange = onReadyStateChangeReplacement; | |
return sendOrig.apply(this, arguments); | |
} | |
function onReadyStateChangeReplacement() { | |
console.warn('HTTP request ready state changed : ' + this.readyState); | |
if (this.readyState == XMLHttpRequest.DONE) { | |
const response = JSON.parse(this.responseText); | |
console.log('response : ',this.__url,response); | |
if (this.__url.includes("/object?")) | |
{ | |
[].concat(response.data).forEach(data => { | |
if (data.component) { | |
const s3Url = data.component.content; | |
window.open.call(window, s3Url) | |
} | |
}) | |
} | |
} | |
if(this._onreadystatechange) { | |
return this._onreadystatechange.apply(this, arguments); | |
} | |
} | |
window.XMLHttpRequest.prototype.open = openReplacement; | |
window.XMLHttpRequest.prototype.send = sendReplacement; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For changing the response :