Skip to content

Commit

Permalink
Merge pull request #27 from amplitude/AMP-105355
Browse files Browse the repository at this point in the history
AMP-105355
  • Loading branch information
jxiwang authored Aug 6, 2024
2 parents fb075f1 + 69fe681 commit e50fc08
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/no-neg-lookbehind.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@amplitude/rrweb-snapshot': patch
'@amplitude/rrweb': patch
---

Replay: Replace negative lookbehind in regexes from css parser as it causes issues with Safari 16
5 changes: 5 additions & 0 deletions .changeset/silent-plants-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@amplitude/rrweb': patch
---

Return early for child same origin frames
18 changes: 14 additions & 4 deletions packages/rrweb-snapshot/src/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,17 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet {
* Parse selector.
*/

// originally from https://github.com/NxtChg/pieces/blob/3eb39c8287a97632e9347a24f333d52d916bc816/js/css_parser/css_parse.js#L46C1-L47C1
const selectorMatcher = new RegExp(
'^((' +
[
/[^\\]"(?:\\"|[^"])*"/.source, // consume any quoted parts (checking that the double quote isn't itself escaped)
/[^\\]'(?:\\'|[^'])*'/.source, // same but for single quotes
'[^{]',
].join('|') +
')+)',
);

function selector() {
whitespace();
while (css[0] == '}') {
Expand All @@ -432,8 +443,7 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet {
whitespace();
}

// Use match logic from https://github.com/NxtChg/pieces/blob/3eb39c8287a97632e9347a24f333d52d916bc816/js/css_parser/css_parse.js#L46C1-L47C1
const m = match(/^(((?<!\\)"(?:\\"|[^"])*"|(?<!\\)'(?:\\'|[^'])*'|[^{])+)/);
const m = match(selectorMatcher);
if (!m) {
return;
}
Expand Down Expand Up @@ -869,8 +879,8 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet {
name +
'\\s*((?:' +
[
'(?<!\\\\)"(?:\\\\"|[^"])*"',
"(?<!\\\\)'(?:\\\\'|[^'])*'",
/[^\\]"(?:\\"|[^"])*"/.source, // consume any quoted parts (checking that the double quote isn't itself escaped)
/[^\\]'(?:\\'|[^'])*'/.source, // same but for single quotes
'[^;]',
].join('|') +
')+);',
Expand Down

0 comments on commit e50fc08

Please sign in to comment.