Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructed stylesheets snapshotted, rebuilt with rrweb-snapshot #1588

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
7 changes: 6 additions & 1 deletion packages/rrweb-snapshot/src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export function buildStyleNode(
}

function buildNode(
n: serializedNodeWithId,
n: serializedNodeWithId & { rrwebAdoptedStylesheets?: string[] },
options: {
doc: Document;
hackCss: boolean;
Expand Down Expand Up @@ -380,6 +380,11 @@ function buildNode(
*/
if (!node.shadowRoot) {
node.attachShadow({ mode: 'open' });
n.rrwebAdoptedStylesheets?.forEach((rrwebAdoptedStylesheet) => {
const styleSheet = new CSSStyleSheet();
styleSheet.replaceSync(rrwebAdoptedStylesheet);
node.shadowRoot?.adoptedStyleSheets.push(styleSheet);
});
} else {
while (node.shadowRoot.firstChild) {
node.shadowRoot.removeChild(node.shadowRoot.firstChild);
Expand Down
14 changes: 12 additions & 2 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
// should warn? maybe a text node isn't attached to a parent node yet?
return false;
} else {
el = dom.parentElement(node)!;

Check warning on line 283 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L283

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
}
try {
if (typeof maskTextClass === 'string') {
Expand Down Expand Up @@ -700,10 +700,10 @@
const recordInlineImage = () => {
image.removeEventListener('load', recordInlineImage);
try {
canvasService!.width = image.naturalWidth;

Check warning on line 703 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L703

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
canvasService!.height = image.naturalHeight;

Check warning on line 704 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L704

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
canvasCtx!.drawImage(image, 0, 0);

Check warning on line 705 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L705

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
attributes.rr_dataURL = canvasService!.toDataURL(

Check warning on line 706 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L706

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
dataURLOptions.type,
dataURLOptions.quality,
);
Expand Down Expand Up @@ -1008,7 +1008,10 @@
id = genId();
}

const serializedNode = Object.assign(_serializedNode, { id });
const serializedNode: serializedNode & {
id: number;
rrwebAdoptedStylesheets?: Array<string | null>;
} = Object.assign(_serializedNode, { id });
// add IGNORED_NODE to mirror to track nextSiblings
mirror.add(n, serializedNode);

Expand All @@ -1025,8 +1028,15 @@
// this property was not needed in replay side
delete serializedNode.needBlock;
const shadowRootEl = dom.shadowRoot(n);
if (shadowRootEl && isNativeShadowDom(shadowRootEl))
if (shadowRootEl && isNativeShadowDom(shadowRootEl)) {
serializedNode.isShadowHost = true;
if (shadowRootEl.adoptedStyleSheets.length > 0) {
serializedNode.rrwebAdoptedStylesheets =
shadowRootEl.adoptedStyleSheets.map((stylesheet) =>
stringifyStylesheet(stylesheet),
);
}
}
}
if (
(serializedNode.type === NodeType.Document ||
Expand Down
Loading