@watchforge/browser 0.1.17 → 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/stacktrace.js +14 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@watchforge/browser",
3
- "version": "0.1.17",
3
+ "version": "0.1.20",
4
4
  "main": "./src/index.js",
5
5
  "types": "./src/index.d.ts",
6
6
  "description": "WatchForge JavaScript SDK for browser JavaScript, Next.js, React, Node.js, and Express.js",
package/src/stacktrace.js CHANGED
@@ -139,7 +139,7 @@ function isJsonParseError(message) {
139
139
 
140
140
  function isUriError(message) {
141
141
  if (!message || typeof message !== "string") return false;
142
- return /URI(?:Error| malformed)/i.test(message) || /decodeURIComponent/i.test(message);
142
+ return /URI\s+malformed/i.test(message) || /URIError/i.test(message);
143
143
  }
144
144
 
145
145
  function isInvalidArrayLengthError(message) {
@@ -717,13 +717,19 @@ function resolveFrameLine(frame, lines) {
717
717
  return lineno;
718
718
  }
719
719
 
720
+ function applyResolvedSourceContext(frame, sourceLines) {
721
+ if (!sourceLines?.length) return false;
722
+ const lineno = resolveFrameLine(frame, sourceLines);
723
+ applySourceContext(frame, sourceLines, lineno);
724
+ return Boolean(frame.context_line);
725
+ }
726
+
720
727
  async function enrichFrameWithNodeSource(frame) {
721
728
  if (!frame.in_app || !frame.lineno) return;
722
729
  const lines = await readNodeSourceLines(frame.raw_abs_path || frame.abs_path);
723
730
  if (!lines) return;
724
731
 
725
- const lineno = resolveFrameLine(frame, lines);
726
- applySourceContext(frame, lines, lineno);
732
+ applyResolvedSourceContext(frame, lines);
727
733
  }
728
734
 
729
735
  function getBrowserSourceFetchCandidates(absPath, rawAbsPath) {
@@ -917,12 +923,10 @@ function applyOriginalSourceFrameContext(frame, sourceMap) {
917
923
 
918
924
  const sourceContent = getSourceMapContentForFrame(frame, sourceMap);
919
925
  if (!sourceContent?.lines?.length) return false;
920
- if (frame.lineno > sourceContent.lines.length) return false;
921
926
 
922
927
  frame.abs_path = sourceContent.source;
923
928
  frame.filename = normalizeSourcePath(sourceContent.source).split("/").pop() || frame.filename;
924
- applySourceContext(frame, sourceContent.lines, frame.lineno);
925
- return Boolean(frame.context_line);
929
+ return applyResolvedSourceContext(frame, sourceContent.lines);
926
930
  }
927
931
 
928
932
  async function findSourceMapForFrame(frame) {
@@ -1081,12 +1085,9 @@ function getWebpackFrameArtifacts(frame) {
1081
1085
  async function enrichFrameWithBrowserSource(frame) {
1082
1086
  if (!frame.in_app || !frame.lineno) return;
1083
1087
 
1084
- if (isOriginalSourceFrame(frame)) {
1085
- const lines = await fetchBrowserSourceLines(frame.abs_path, frame.raw_abs_path);
1086
- if (lines) {
1087
- applySourceContext(frame, lines, frame.lineno);
1088
- if (frame.context_line) return;
1089
- }
1088
+ const lines = await fetchBrowserSourceLines(frame.abs_path, frame.raw_abs_path);
1089
+ if (lines && applyResolvedSourceContext(frame, lines)) {
1090
+ return;
1090
1091
  }
1091
1092
 
1092
1093
  const webpackArtifacts = getWebpackFrameArtifacts(frame);
@@ -1096,16 +1097,7 @@ async function enrichFrameWithBrowserSource(frame) {
1096
1097
  }
1097
1098
 
1098
1099
  if (webpackArtifacts?.lines && !webpackArtifacts?.sourceMap) {
1099
- const lineno = resolveFrameLine(frame, webpackArtifacts.lines);
1100
- applySourceContext(frame, webpackArtifacts.lines, lineno);
1101
- if (frame.context_line) return;
1102
- }
1103
-
1104
- const lines = await fetchBrowserSourceLines(frame.abs_path, frame.raw_abs_path);
1105
- if (lines) {
1106
- const lineno = resolveFrameLine(frame, lines);
1107
- applySourceContext(frame, lines, lineno);
1108
- if (frame.context_line) return;
1100
+ if (applyResolvedSourceContext(frame, webpackArtifacts.lines)) return;
1109
1101
  }
1110
1102
 
1111
1103
  await enrichFrameWithSourceMap(frame);