Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add opt for sourcemap URL transform #39

Open
jakelauer opened this issue Aug 9, 2019 · 0 comments

Comments

@jakelauer
Copy link

commented Aug 9, 2019

The problem
Often, it is preferable for developers to keep sourcemaps private in production, so users cannot browse through the source easily. However, disabling sourcemaps in production makes logging stack traces almost pointless. This library fixes that particular issue, but with the side effect of requiring public sourcemaps which the browser can read.

Proposed solution
Developers could generate sourcemaps as normal, such that .js files include the sourcemap URL, but could avoid putting the sourcemaps at the location specified. That way, the browser will not be able to find the sourcemap and users will not be able to debug the real source in the debugger.

Developers could put the sourcemaps in a different location (e.g. /sourcemaps/*.js.map). Then, when the user uses mapStackTrace, then could do so like this:

try {
  // break something
  bork();
} catch (e) {
  // pass e.stack to window.mapStackTrace
  window.mapStackTrace(e.stack, function(mappedStack) {
    // do what you want with mappedStack here
    console.log(mappedStack.join("\n"));
  }, {
    sourceMappingUrlTransform: (originalUrl) => {
        return `/sourcemaps/${originalUrl}`;
    }
  });
}

With the above code, sourceMappingUrlTransform is passed the original URL (e.g. 4.4b60831e.chunk.js.map) and can return the preferred .map URL (/sourcemaps/4.4b60831e.chunk.js.map).

Result
With the above change, developers would be able to prevent the browser from easily reading sourcemaps, while still gaining effective error logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.