Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akirattii/f0c625dbe9db3b0bccbd6b946c75bdd9 to your computer and use it in GitHub Desktop.
Save akirattii/f0c625dbe9db3b0bccbd6b946c75bdd9 to your computer and use it in GitHub Desktop.
Over the unsafe header restriction of Chrome apps using WSC.ChromeSocketXMLHttpRequest
// 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