Last active
February 26, 2018 09:05
-
-
Save javajosh/ca5a17aa42d4523f129f130ec5849149 to your computer and use it in GitHub Desktop.
Chrome extension that fails to adjust HTTP status line code.
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
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']); |
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
{ | |
"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/" | |
] | |
} |
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
<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