Skip to content

Commit

Permalink
Catch Security Errors in styleSheet rules (rrweb-io#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
grziwok authored Dec 10, 2020
1 parent 4b589b3 commit 714a4fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode
.idea
node_modules
package-lock.json
# yarn.lock
Expand Down
21 changes: 14 additions & 7 deletions src/replay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,16 +849,23 @@ export class Replayer {

if (d.adds) {
d.adds.forEach(({ rule, index }) => {
const _index =
index === undefined
? undefined
: Math.min(index, styleSheet.rules.length);
try {
styleSheet.insertRule(rule, _index);
const _index =
index === undefined
? undefined
: Math.min(index, styleSheet.rules.length);
try {
styleSheet.insertRule(rule, _index);
} catch (e) {
/**
* sometimes we may capture rules with browser prefix
* insert rule with prefixs in other browsers may cause Error
*/
}
} catch (e) {
/**
* sometimes we may capture rules with browser prefix
* insert rule with prefixs in other browsers may cause Error
* accessing styleSheet rules may cause SecurityError
* for specific access control settings
*/
}
});
Expand Down

0 comments on commit 714a4fb

Please sign in to comment.