Skip to content

Instantly share code, notes, and snippets.

@javajosh
Last active February 26, 2018 09:05
Show Gist options
  • Save javajosh/ca5a17aa42d4523f129f130ec5849149 to your computer and use it in GitHub Desktop.
Save javajosh/ca5a17aa42d4523f129f130ec5849149 to your computer and use it in GitHub Desktop.
Chrome extension that fails to adjust HTTP status line code.
let count = 0;
function listener1(details){
return {cancel: true};
}
function listener2(details){
console.log(count++, details);
if (!details) return;
for (let i = 0; i < details.responseHeaders.length; i++){
if (details.responseHeaders[i].name === 'status'){
details.responseHeaders[i].value = '500';
break;
}
}
details.responseHeaders.push({name: 'josh', value: 'count: ' + count});
// Response is of type "Blocking Response"
return {responseHeaders: details.responseHeaders};
}
// Cancel and response headers cannot be combined.
function listener3(details){
console.log(count++, details);
if (!details) return;
for (let i = 0; i < details.responseHeaders.length; i++){
if (details.responseHeaders[i].name === 'status'){
details.responseHeaders[i].value = '500';
break;
}
}
details.responseHeaders.push({name: 'josh', value: 'count: ' + count});
// Response is of type "Blocking Response"
return {cancel: true, responseHeaders: []};
}
const filter1 = '<all_urls>';
const filter2 = 'https://www.google.com/'
chrome.webRequest.onHeadersReceived.addListener(listener2, { urls: [filter2] }, ['blocking', 'responseHeaders']);
{
"name": "Server Error Simulation Extension",
"description" : "Base Level Extension",
"version": "1.0",
"manifest_version": 2,
"browser_action": {
"default_popup": "popup.html",
"default_icon": "logo.png"
},
"background": {
"persistent": true,
"scripts": ["background.js"]
},
"permissions": [
"activeTab",
"storage",
"webRequest",
"webRequestBlocking",
"*://*.com/"
]
}
<html>
<body>
<h1>Simulate Error</h1>
</body>
<form>
<input type="text" placeholder="pattern">
<input type="number" placeholder="503">
</form>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment