node-source-map-support icon indicating copy to clipboard operation
node-source-map-support copied to clipboard

Refused to get unsafe header "SourceMap"

Open dignifiedquire opened this issue 10 years ago • 6 comments

I'm trying to use this module in the browser in combination with bluebird and webpack.

I'm loading it via import 'source-map-support/register' and all builds fine but when I run the code in the browser I throws

Refused to get unsafe header "SourceMap"
Refused to get unsafe header "X-SourceMap"

any ideas what is going wrong here?

  • Chrome Version 43.0.2357.81 (64-bit) (Mac)
  • [email protected] node_modules/source-map-support

screen shot 2015-06-01 at 12 38 34 screen shot 2015-06-01 at 12 38 24

dignifiedquire avatar Jun 01 '15 10:06 dignifiedquire

@Dignifiedquire: Not sure if you're using webpack-dev-server too, but we saw the same thing and have set the following headers option:

new WebpackDevServer(compiler, {
  ...
  headers: { 'Access-Control-Expose-Headers': 'SourceMap,X-SourceMap' }
  ...
});

See:

tanem avatar Aug 20 '15 00:08 tanem

While exposing the appropriate headers is definitely a must when source maps are being sent over the network, I might argue that trying to access these headers is entirely unnecessary when the source maps are inlined. I would suggest that this library first check if sourcemaps are already present and only if not try to access these headers to check if there are sourcemaps available through the network.

call-a3 avatar Sep 29 '15 14:09 call-a3

Is there any known solution to this issue?

adamziel avatar Feb 04 '16 20:02 adamziel

FYI the workaround that worked for me was to use inline source maps and remove this code block:

  if (isInBrowser()) {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', source, false);
    xhr.send(null);
    fileData = xhr.readyState === 4 ? xhr.responseText : null;

    // Support providing a sourceMappingURL via the SourceMap header
    var sourceMapHeader = xhr.getResponseHeader("SourceMap") ||
                          xhr.getResponseHeader("X-SourceMap");
    if (sourceMapHeader) {
      return sourceMapHeader;
    }
  }

adamziel avatar Feb 04 '16 21:02 adamziel

Any updates on this? I'm sill seeing the same issue from that same code block.

wbt avatar Aug 24 '20 18:08 wbt

I'm getting this also

andy-root avatar Apr 22 '24 20:04 andy-root