Chrome: Add local JavaScript SourceMap possible?

10,354

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.

Share:
10,354

Related videos on Youtube

agrafix
Author by

agrafix

Updated on July 13, 2022

Comments

  • agrafix
    agrafix almost 2 years

    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?

    • Barmar
      Barmar over 10 years
      See developers.google.com/chrome-developer-tools/docs/… for how the location of the source map is found.
    • agrafix
      agrafix over 10 years
      I don't think you can reference local files there?
    • Tyler
      Tyler over 10 years
      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 :(
  • KennyXu
    KennyXu almost 6 years
    in chrome you can right click the source file and select add source map...
  • Kazuki
    Kazuki almost 5 years
    @KennyXu Do you know if it's still available? I cannot see UI to add sourcemap
  • Mike Stapp
    Mike Stapp almost 5 years
    @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.
  • Kazuki
    Kazuki almost 5 years
    Ahh, I was right clicking on the filename. It seems right clicking on the source code was the key. Thanks for help.