This is a screenshot of Edge's debugger window. The code isn't running, but as you can see, there are little red squigglies in the debugger window; the interpreter/compiler/whatsit isn't happy, but there is no indication of what it doesn't like specifically. The output window is clear, there is no "hover tip", nor any other explanation I can find.
This is practically a direct copy of the example from the MDN docs.
Any guidance is immensely appreciated.
As mentioned in the comments, it appears to be the support isn't there from the browser you are using. So I would suggest changing the iteration from a for..of
to a for..in
. Something along the lines of (edited from @agrm's fiddle):
function rewriteUserAgentHeader(e) {
for (var index in e.requestHeaders) {
if (e.requestHeaders[index].name.toLowerCase() === "user-agent")
{ e.requestHeaders[index].value = "it worked!"; }
}
return {requestHeaders: e.requestHeaders};
}
var headers = {
requestHeaders: [
{name: "user-agent", value: "to be modified"},
{name: "something-else", value: "to be left alone"}
]
};
console.log( rewriteUserAgentHeader(headers) )