Skip to content

Commit ac5034e

Browse files
committed
wrap mutation callbacks in try-catch
1 parent a7bad97 commit ac5034e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/util/mutations.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ const addedNodesPool = [];
77
let repaintQueued = false;
88
let timerId;
99

10+
const isolateErrors = func => {
11+
try {
12+
func();
13+
} catch (exception) {
14+
console.error(exception);
15+
}
16+
};
17+
1018
export const pageModifications = Object.freeze({
1119
listeners: new Map(),
1220

@@ -41,7 +49,7 @@ export const pageModifications = Object.freeze({
4149
if (modifierFunction.length === 0) {
4250
const shouldRun =
4351
rootNode.querySelector(selector) !== null || headNode.querySelector(selector) !== null;
44-
if (shouldRun) modifierFunction();
52+
if (shouldRun) isolateErrors(() => modifierFunction());
4553
return;
4654
}
4755

@@ -77,7 +85,7 @@ const onBeforeRepaint = () => {
7785
for (const [modifierFunction, selector] of pageModifications.listeners) {
7886
if (modifierFunction.length === 0) {
7987
const shouldRun = addedNodes.some(addedNode => addedNode.matches(selector) || addedNode.querySelector(selector) !== null);
80-
if (shouldRun) modifierFunction();
88+
if (shouldRun) isolateErrors(() => modifierFunction());
8189
continue;
8290
}
8391

@@ -87,7 +95,7 @@ const onBeforeRepaint = () => {
8795
].filter((value, index, array) => index === array.indexOf(value));
8896

8997
if (matchingElements.length !== 0) {
90-
modifierFunction(matchingElements);
98+
isolateErrors(() => modifierFunction(matchingElements));
9199
}
92100
}
93101
};

0 commit comments

Comments
 (0)