Created
July 14, 2016 12:05
-
-
Save akirattii/f0c625dbe9db3b0bccbd6b946c75bdd9 to your computer and use it in GitHub Desktop.
Over the unsafe header restriction of Chrome apps using WSC.ChromeSocketXMLHttpRequest
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
// First, | |
// $ git clone https://github.com/kzahel/web-server-chrome.git | |
// $ ./minimize.sh | |
// and ... | |
// load wsc-chrome.min.js in your html | |
function request(url, headers, cb) { | |
let xhr = new WSC.ChromeSocketXMLHttpRequest; | |
let headersLen = headers.length; | |
let k, v; | |
for (let i = 0; i < headersLen; i++) { | |
[k, v] = headers[i]; | |
xhr.setRequestHeader(k, v); | |
} | |
xhr.open("GET", url); | |
xhr.timeout = TIMEOUT; | |
xhr.onload = xhr.onerror = xhr.ontimeout = function(evt) { | |
console.log('xhr result:', evt); | |
return cb(evt); | |
} | |
xhr.send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment