Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I enable sourcemaps in a chrome extension?

I'm doing some test development and creating a Chrome extension using Svelte and ParcelJS and would like to see the sourcemaps in chrome dev tools. When looking at any page however I can only see the bundled code see this error:

DevTools failed to load SourceMap: Could not load content for chrome-extension://debafkiakedogoflaalmbbfbbccnfbib/Background/index.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME

It seems the loader does not like the chrome-extension url scheme. I've tried adding 'dist' as an override directory, but whatever loads the sourcemaps seems to ignore it and still uses the 'chrome-extension` scheme.

I am able to get it working by manually changing the url to another schema, either a file:/// url or running a simple http server in the dist directory and using an http:// url:

//# sourceMappingURL=file:///c:/git/svelte-extension/dist//Background/index.js.map`
//# sourceMappingURL=http://localhost:8080/Background/index.js.map`

Is there a way to either get chrome to override the directory or tell parcel to create those urls?

like image 596
Jason Goemaat Avatar asked Apr 27 '20 15:04

Jason Goemaat


People also ask

Should I use Sourcemaps production?

Most JavaScript and CSS sources are usually minified and source maps serve as a memory map to the compressed files. It's generally a good practice to minify and combine your assets (Javascript & CSS) when deploying to production.

What is the use of Sourcemaps?

A source map is a file that maps from the transformed source to the original source, enabling the browser to reconstruct the original source and present the reconstructed original in the debugger.


1 Answers

Try using inline sourcemaps during development. Chrome won't load Chrome extension sourcemap files, but inline sourcemaps do work.

Background

Chrome has always silently failed to load sourcemap files from the chrome-extension:// URL scheme. Chrome v80 started reporting the DevTools failed to load SourceMap error.

This may change soon, as there is a fix in the works. Some security concerns are holding this back, so keep your fingers crossed.

Here are two relevant Chromium bugs tracking this:

  1. https://bugs.chromium.org/p/chromium/issues/detail?id=1052872#c14
  2. https://bugs.chromium.org/p/chromium/issues/detail?id=1053535
like image 78
Jack Steam Avatar answered Oct 17 '22 22:10

Jack Steam