2

enter image description here

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.

Scott Baker
  • 10,013
  • 17
  • 56
  • 102
  • 5
    Edge 12? Because that is the lowest Edge support for of – mplungjan Nov 30 '17 at 21:41
  • Not sure if I'm looking at the right version, but I'm using "`Microsoft Edge 38.14393.1066.0`" and "`Microsoft EdgeHTML 14.14393`" according to the Settings dialog – Scott Baker Nov 30 '17 at 21:58
  • I put the function in a [fiddle](https://jsfiddle.net/kju1y4oe/) and it runs smooth at least in Edge 15 :o) – agrm Nov 30 '17 at 22:09

1 Answers1

0

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) )
andrewf
  • 375
  • 4
  • 10