Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/rrweb/src/record/error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export function unregisterErrorHandler() {
/**
* Wrap callbacks in a wrapper that allows to pass errors to a configured `errorHandler` method.
*/
export const callbackWrapper = <T extends Callback>(cb: T): T => {
export const callbackWrapper = <T extends Callback>(
cb: T,
errorSource?: string,
): T => {
if (!errorHandler) {
return cb;
}
Expand All @@ -24,6 +27,13 @@ export const callbackWrapper = <T extends Callback>(cb: T): T => {
try {
return cb(...rest);
} catch (error) {
// Some libraries (styled-components) rely on an exception to be thrown.
// Attach an optional property here to allow `errorHandler` to make
// additional decisions (e.g. to re-throw).
if (errorSource) {
error.__source__ = errorSource;
}
Comment on lines +33 to +35
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this only happens if we have errorHandler defined, this probably only affects us. I opted to make this generic so that errorHandler be the source of truth vs attaching a meta property like __allowThrow__


if (errorHandler && errorHandler(error) === true) {
return () => {
// This will get called by `record()`'s cleanup function
Expand Down
2 changes: 2 additions & 0 deletions packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ function initStyleSheetObserver(
}
return target.apply(thisArg, argumentsList);
},
'CSSStyleSheet.insertRule',
),
});

Expand Down Expand Up @@ -891,6 +892,7 @@ function initStyleSheetObserver(
}
return target.apply(thisArg, argumentsList);
},
'CSSStyleSheet.insertRule',
),
},
);
Expand Down