33

Is it possible to add a local SourceMap? I have a Website, which I cannot modify, containing compressed (closure) JavaScript. I have a local JavaScript-SourceMap belonging to that file. Is there any way to tell GoogleChrome (or any other browser) to add a SourceMap before/after the page loads?

agrafix
  • 765
  • 1
  • 5
  • 15
  • See https://developers.google.com/chrome-developer-tools/docs/javascript-debugging#source-maps for how the location of the source map is found. – Barmar Feb 11 '14 at 16:51
  • I don't think you can reference local files there? – agrafix Feb 11 '14 at 19:12
  • 1
    Maybe you can use a Chrome extension to intercept the HTTP request for the JavaScript and insert the X-SourceMap header? Still not sure if it will work with a file:// URL though :( – Tyler Feb 15 '14 at 18:18

1 Answers1

12

You cannot point to file containing the map. You can however host your map locally and then point to localhost address. In the javascript source file there also must not be

//# sourceMappingURL=...

comment presented since than Chrome DevTools won't load the sourcemap if it is different than specified in the URL.

greatwolf
  • 20,287
  • 13
  • 71
  • 105
JeFf
  • 346
  • 5
  • 16
  • 4
    in chrome you can right click the source file and select add source map... – KennyXu Aug 28 '18 at 10:59
  • 3
    @KennyXu Do you know if it's still available? I cannot see UI to add sourcemap – Kazuki Aug 20 '19 at 00:41
  • 12
    @Kazuki In the Sources tab, select the bundled .js file you want (e.g. app.js), then right click in the pane showing that bundled file's source code. That's where you'll see the "Add source map..." option. – Mike Stapp Sep 23 '19 at 16:44
  • 4
    Ahh, I was right clicking on the filename. It seems right clicking on the source code was the key. Thanks for help. – Kazuki Sep 24 '19 at 02:45