Feature Request: Add opt for sourcemap URL transform
Opened this issue · 0 comments
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.