Automate NPM package releases (#1119)

This commit is contained in:
Justin Halsall
2026-04-01 12:00:00 +08:00
committed by GitHub
parent 19be06d936
commit 27caffecff
43 changed files with 1300 additions and 392 deletions

8
.changeset/README.md Normal file
View File

@@ -0,0 +1,8 @@
# Changesets
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

11
.changeset/config.json Normal file
View File

@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": []
}

13
.changeset/pre.json Normal file
View File

@@ -0,0 +1,13 @@
{
"mode": "pre",
"tag": "alpha",
"initialVersions": {
"rrdom": "0.1.7",
"rrdom-nodejs": "0.1.7",
"rrweb": "2.0.0-alpha.4",
"rrweb-player": "1.0.0-alpha.4",
"rrweb-snapshot": "2.0.0-alpha.4",
"@rrweb/types": "2.0.0-alpha.4"
},
"changesets": []
}

38
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,38 @@
name: Release
on:
push:
branches:
- master
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Node.js lts/*
uses: actions/setup-node@v3
with:
node-version: lts/*
- name: Install Dependencies
run: yarn
- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
publish: yarn run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# - name: Send a Slack notification if a publish happens
# if: steps.changesets.outputs.published == 'true'
# # You can do something when a publish happens.
# run: my-slack-bot send-notification --message "A new version of ${GITHUB_REPOSITORY} was published!"

View File

@@ -18,6 +18,7 @@
"packages/*" "packages/*"
], ],
"devDependencies": { "devDependencies": {
"@changesets/cli": "^2.26.0",
"@monorepo-utils/workspaces-to-typescript-project-references": "^2.8.2", "@monorepo-utils/workspaces-to-typescript-project-references": "^2.8.2",
"@typescript-eslint/eslint-plugin": "^5.25.0", "@typescript-eslint/eslint-plugin": "^5.25.0",
"@typescript-eslint/parser": "^5.25.0", "@typescript-eslint/parser": "^5.25.0",
@@ -42,7 +43,8 @@
"repl": "cd packages/rrweb && npm run repl", "repl": "cd packages/rrweb && npm run repl",
"live-stream": "cd packages/rrweb && yarn live-stream", "live-stream": "cd packages/rrweb && yarn live-stream",
"lint": "yarn run concurrently --success=all -r -m=1 'yarn run markdownlint docs' 'yarn eslint packages/*/src --ext .ts,.tsx,.js,.jsx,.svelte'", "lint": "yarn run concurrently --success=all -r -m=1 'yarn run markdownlint docs' 'yarn eslint packages/*/src --ext .ts,.tsx,.js,.jsx,.svelte'",
"lint:report": "yarn eslint --output-file eslint_report.json --format json packages/*/src --ext .ts,.tsx,.js,.jsx" "lint:report": "yarn eslint --output-file eslint_report.json --format json packages/*/src --ext .ts,.tsx,.js,.jsx",
"release": "yarn build:all && changeset publish"
}, },
"resolutions": { "resolutions": {
"**/jsdom/cssom": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.6.0.tgz" "**/jsdom/cssom": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.6.0.tgz"

View File

@@ -36,15 +36,16 @@ export class RRWindow {
export class RRDocument export class RRDocument
extends BaseRRDocumentImpl(RRNode) extends BaseRRDocumentImpl(RRNode)
implements IRRDocument { implements IRRDocument
{
readonly nodeName: '#document' = '#document'; readonly nodeName: '#document' = '#document';
private _nwsapi: NWSAPI; private _nwsapi: NWSAPI;
get nwsapi() { get nwsapi() {
if (!this._nwsapi) { if (!this._nwsapi) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
this._nwsapi = nwsapi({ this._nwsapi = nwsapi({
document: (this as unknown) as Document, document: this as unknown as Document,
DOMException: (null as unknown) as new ( DOMException: null as unknown as new (
message?: string, message?: string,
name?: string, name?: string,
) => DOMException, ) => DOMException,
@@ -97,7 +98,7 @@ export class RRDocument
} }
querySelectorAll(selectors: string): RRNode[] { querySelectorAll(selectors: string): RRNode[] {
return (this.nwsapi.select(selectors) as unknown) as RRNode[]; return this.nwsapi.select(selectors) as unknown as RRNode[];
} }
getElementsByTagName(tagName: string): RRElement[] { getElementsByTagName(tagName: string): RRElement[] {
@@ -220,7 +221,7 @@ export class RRElement extends BaseRRElementImpl(RRNode) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
get style() { get style() {
return (this._style as unknown) as CSSStyleDeclaration; return this._style as unknown as CSSStyleDeclaration;
} }
attachShadow(_init: ShadowRootInit): RRElement { attachShadow(_init: ShadowRootInit): RRElement {
@@ -268,14 +269,14 @@ export class RRElement extends BaseRRElementImpl(RRNode) {
querySelectorAll(selectors: string): RRNode[] { querySelectorAll(selectors: string): RRNode[] {
const result: RRElement[] = []; const result: RRElement[] = [];
if (this.ownerDocument !== null) { if (this.ownerDocument !== null) {
((this.ownerDocument as RRDocument).nwsapi.select( (this.ownerDocument as RRDocument).nwsapi.select(
selectors, selectors,
(this as unknown) as Element, this as unknown as Element,
(element) => { (element) => {
if (((element as unknown) as RRElement) !== this) if ((element as unknown as RRElement) !== this)
result.push((element as unknown) as RRElement); result.push(element as unknown as RRElement);
}, },
) as unknown) as RRNode[]; ) as unknown as RRNode[];
} }
return result; return result;
} }
@@ -393,6 +394,5 @@ interface RRElementTagNameMap {
video: RRMediaElement; video: RRMediaElement;
} }
type RRElementType< type RRElementType<K extends keyof HTMLElementTagNameMap> =
K extends keyof HTMLElementTagNameMap K extends keyof RRElementTagNameMap ? RRElementTagNameMap[K] : RRElement;
> = K extends keyof RRElementTagNameMap ? RRElementTagNameMap[K] : RRElement;

View File

@@ -51,10 +51,10 @@ export function polyfillRAF() {
} }
} }
(global as Window & (global as Window & typeof globalThis).requestAnimationFrame =
typeof globalThis).requestAnimationFrame = requestAnimationFrame; requestAnimationFrame;
(global as Window & (global as Window & typeof globalThis).cancelAnimationFrame =
typeof globalThis).cancelAnimationFrame = cancelAnimationFrame; cancelAnimationFrame;
} }
/** /**
@@ -88,5 +88,5 @@ export function polyfillDocument() {
rrdom.documentElement!.appendChild(rrdom.createElement('head')); rrdom.documentElement!.appendChild(rrdom.createElement('head'));
rrdom.documentElement!.appendChild(rrdom.createElement('body')); rrdom.documentElement!.appendChild(rrdom.createElement('body'));
})(); })();
global.document = (rrdom as unknown) as Document; global.document = rrdom as unknown as Document;
} }

View File

@@ -26,7 +26,7 @@ describe('polyfill for nodejs', () => {
polyfillPerformance(); polyfillPerformance();
expect(global.performance).toBe(originalPerformance); expect(global.performance).toBe(originalPerformance);
} }
const fakePerformance = (jest.fn() as unknown) as Performance; const fakePerformance = jest.fn() as unknown as Performance;
global.performance = fakePerformance; global.performance = fakePerformance;
polyfillPerformance(); polyfillPerformance();
expect(global.performance).toEqual(fakePerformance); expect(global.performance).toEqual(fakePerformance);
@@ -72,9 +72,11 @@ describe('polyfill for nodejs', () => {
}); });
it('should not polyfill requestAnimationFrame if it already exists', () => { it('should not polyfill requestAnimationFrame if it already exists', () => {
const fakeRequestAnimationFrame = (jest.fn() as unknown) as typeof global.requestAnimationFrame; const fakeRequestAnimationFrame =
jest.fn() as unknown as typeof global.requestAnimationFrame;
global.requestAnimationFrame = fakeRequestAnimationFrame; global.requestAnimationFrame = fakeRequestAnimationFrame;
const fakeCancelAnimationFrame = (jest.fn() as unknown) as typeof global.cancelAnimationFrame; const fakeCancelAnimationFrame =
jest.fn() as unknown as typeof global.cancelAnimationFrame;
global.cancelAnimationFrame = fakeCancelAnimationFrame; global.cancelAnimationFrame = fakeCancelAnimationFrame;
polyfillRAF(); polyfillRAF();
expect(global.requestAnimationFrame).toBe(fakeRequestAnimationFrame); expect(global.requestAnimationFrame).toBe(fakeRequestAnimationFrame);
@@ -91,7 +93,7 @@ describe('polyfill for nodejs', () => {
}); });
it('should not polyfill Event type if it already exists', () => { it('should not polyfill Event type if it already exists', () => {
const fakeEvent = (jest.fn() as unknown) as typeof global.Event; const fakeEvent = jest.fn() as unknown as typeof global.Event;
global.Event = fakeEvent; global.Event = fakeEvent;
polyfillEvent(); polyfillEvent();
expect(global.Event).toBe(fakeEvent); expect(global.Event).toBe(fakeEvent);
@@ -106,7 +108,7 @@ describe('polyfill for nodejs', () => {
}); });
it('should not polyfill Node type if it already exists', () => { it('should not polyfill Node type if it already exists', () => {
const fakeNode = (jest.fn() as unknown) as typeof global.Node; const fakeNode = jest.fn() as unknown as typeof global.Node;
global.Node = fakeNode; global.Node = fakeNode;
polyfillNode(); polyfillNode();
expect(global.Node).toBe(fakeNode); expect(global.Node).toBe(fakeNode);
@@ -121,7 +123,7 @@ describe('polyfill for nodejs', () => {
}); });
it('should not polyfill document object if it already exists', () => { it('should not polyfill document object if it already exists', () => {
const fakeDocument = (jest.fn() as unknown) as typeof global.document; const fakeDocument = jest.fn() as unknown as typeof global.document;
global.document = fakeDocument; global.document = fakeDocument;
polyfillDocument(); polyfillDocument();
expect(global.document).toBe(fakeDocument); expect(global.document).toBe(fakeDocument);

View File

@@ -301,10 +301,9 @@ function diffAfterUpdatingChildren(
oldTree.textContent !== oldTree.textContent !==
(newTree as IRRText | IRRComment | IRRCDATASection).data (newTree as IRRText | IRRComment | IRRCDATASection).data
) )
oldTree.textContent = (newTree as oldTree.textContent = (
| IRRText newTree as IRRText | IRRComment | IRRCDATASection
| IRRComment ).data;
| IRRCDATASection).data;
break; break;
} }
} }

View File

@@ -195,7 +195,7 @@ export class BaseRRNode implements IRRNode {
} }
export function BaseRRDocumentImpl< export function BaseRRDocumentImpl<
RRNode extends ConstrainedConstructor<IRRNode> RRNode extends ConstrainedConstructor<IRRNode>,
>(RRNodeClass: RRNode) { >(RRNodeClass: RRNode) {
return class BaseRRDocument extends RRNodeClass implements IRRDocument { return class BaseRRDocument extends RRNodeClass implements IRRDocument {
public readonly nodeType: number = NodeType.DOCUMENT_NODE; public readonly nodeType: number = NodeType.DOCUMENT_NODE;
@@ -401,13 +401,14 @@ export function BaseRRDocumentImpl<
} }
export function BaseRRDocumentTypeImpl< export function BaseRRDocumentTypeImpl<
RRNode extends ConstrainedConstructor<IRRNode> RRNode extends ConstrainedConstructor<IRRNode>,
>(RRNodeClass: RRNode) { >(RRNodeClass: RRNode) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
return class BaseRRDocumentType return class BaseRRDocumentType
extends RRNodeClass extends RRNodeClass
implements IRRDocumentType { implements IRRDocumentType
{
public readonly nodeType: number = NodeType.DOCUMENT_TYPE_NODE; public readonly nodeType: number = NodeType.DOCUMENT_TYPE_NODE;
public readonly RRNodeType = RRNodeType.DocumentType; public readonly RRNodeType = RRNodeType.DocumentType;
public readonly nodeName: string; public readonly nodeName: string;
@@ -431,7 +432,7 @@ export function BaseRRDocumentTypeImpl<
} }
export function BaseRRElementImpl< export function BaseRRElementImpl<
RRNode extends ConstrainedConstructor<IRRNode> RRNode extends ConstrainedConstructor<IRRNode>,
>(RRNodeClass: RRNode) { >(RRNodeClass: RRNode) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
@@ -479,9 +480,9 @@ export function BaseRRElementImpl<
} }
public get style() { public get style() {
const style = (this.attributes.style const style = (
? parseCSSText(this.attributes.style) this.attributes.style ? parseCSSText(this.attributes.style) : {}
: {}) as CSSStyleDeclaration; ) as CSSStyleDeclaration;
const hyphenateRE = /\B([A-Z])/g; const hyphenateRE = /\B([A-Z])/g;
style.setProperty = ( style.setProperty = (
name: string, name: string,
@@ -583,7 +584,7 @@ export function BaseRRElementImpl<
} }
export function BaseRRMediaElementImpl< export function BaseRRMediaElementImpl<
RRElement extends ConstrainedConstructor<IRRElement> RRElement extends ConstrainedConstructor<IRRElement>,
>(RRElementClass: RRElement) { >(RRElementClass: RRElement) {
return class BaseRRMediaElement extends RRElementClass { return class BaseRRMediaElement extends RRElementClass {
public currentTime?: number; public currentTime?: number;
@@ -637,7 +638,7 @@ export function BaseRRTextImpl<RRNode extends ConstrainedConstructor<IRRNode>>(
} }
export function BaseRRCommentImpl< export function BaseRRCommentImpl<
RRNode extends ConstrainedConstructor<IRRNode> RRNode extends ConstrainedConstructor<IRRNode>,
>(RRNodeClass: RRNode) { >(RRNodeClass: RRNode) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
@@ -667,13 +668,14 @@ export function BaseRRCommentImpl<
} }
export function BaseRRCDATASectionImpl< export function BaseRRCDATASectionImpl<
RRNode extends ConstrainedConstructor<IRRNode> RRNode extends ConstrainedConstructor<IRRNode>,
>(RRNodeClass: RRNode) { >(RRNodeClass: RRNode) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
return class BaseRRCDATASection return class BaseRRCDATASection
extends RRNodeClass extends RRNodeClass
implements IRRCDATASection { implements IRRCDATASection
{
public readonly nodeName: '#cdata-section' = '#cdata-section'; public readonly nodeName: '#cdata-section' = '#cdata-section';
public readonly nodeType: number = NodeType.CDATA_SECTION_NODE; public readonly nodeType: number = NodeType.CDATA_SECTION_NODE;
public readonly RRNodeType = RRNodeType.CDATA; public readonly RRNodeType = RRNodeType.CDATA;

View File

@@ -193,9 +193,8 @@ interface RRElementTagNameMap {
video: RRMediaElement; video: RRMediaElement;
} }
type RRElementType< type RRElementType<K extends keyof HTMLElementTagNameMap> =
K extends keyof HTMLElementTagNameMap K extends keyof RRElementTagNameMap ? RRElementTagNameMap[K] : RRElement;
> = K extends keyof RRElementTagNameMap ? RRElementTagNameMap[K] : RRElement;
function getValidTagName(element: HTMLElement): string { function getValidTagName(element: HTMLElement): string {
// https://github.com/rrweb-io/rrweb-snapshot/issues/56 // https://github.com/rrweb-io/rrweb-snapshot/issues/56

View File

@@ -65,9 +65,11 @@ function createTree(
type TNode = typeof rrDocument extends RRDocument ? RRNode : Node; type TNode = typeof rrDocument extends RRDocument ? RRNode : Node;
let root: TNode; let root: TNode;
root = (rrDocument root = (
? rrDocument.createElement(treeNode.tagName) rrDocument
: document.createElement(treeNode.tagName)) as TNode; ? rrDocument.createElement(treeNode.tagName)
: document.createElement(treeNode.tagName)
) as TNode;
const sn = Object.assign({}, elementSn, { const sn = Object.assign({}, elementSn, {
tagName: treeNode.tagName, tagName: treeNode.tagName,
@@ -75,9 +77,9 @@ function createTree(
}); });
if (rrDocument) { if (rrDocument) {
rrDocument.mirror.add((root as unknown) as RRNode, sn); rrDocument.mirror.add(root as unknown as RRNode, sn);
} else { } else {
mirror.add((root as unknown) as Node, sn); mirror.add(root as unknown as Node, sn);
} }
if (treeNode.children) if (treeNode.children)
@@ -320,8 +322,8 @@ describe('diff algorithm for rrdom', () => {
rrNode.attributes = { id: 'node1', class: 'node' }; rrNode.attributes = { id: 'node1', class: 'node' };
diff(node, rrNode, replayer); diff(node, rrNode, replayer);
expect(((node as Node) as HTMLElement).id).toBe('node1'); expect((node as Node as HTMLElement).id).toBe('node1');
expect(((node as Node) as HTMLElement).className).toBe('node'); expect((node as Node as HTMLElement).className).toBe('node');
}); });
it('can update exist properties', () => { it('can update exist properties', () => {
@@ -330,9 +332,9 @@ describe('diff algorithm for rrdom', () => {
const sn = Object.assign({}, elementSn, { tagName }); const sn = Object.assign({}, elementSn, { tagName });
mirror.add(node, sn); mirror.add(node, sn);
((node as Node) as HTMLElement).id = 'element1'; (node as Node as HTMLElement).id = 'element1';
((node as Node) as HTMLElement).className = 'element'; (node as Node as HTMLElement).className = 'element';
((node as Node) as HTMLElement).setAttribute('style', 'color: black'); (node as Node as HTMLElement).setAttribute('style', 'color: black');
const rrDocument = new RRDocument(); const rrDocument = new RRDocument();
const rrNode = rrDocument.createElement(tagName); const rrNode = rrDocument.createElement(tagName);
const sn2 = Object.assign({}, elementSn, { tagName }); const sn2 = Object.assign({}, elementSn, { tagName });
@@ -340,17 +342,17 @@ describe('diff algorithm for rrdom', () => {
rrNode.attributes = { id: 'node1', class: 'node', style: 'color: white' }; rrNode.attributes = { id: 'node1', class: 'node', style: 'color: white' };
diff(node, rrNode, replayer); diff(node, rrNode, replayer);
expect(((node as Node) as HTMLElement).id).toBe('node1'); expect((node as Node as HTMLElement).id).toBe('node1');
expect(((node as Node) as HTMLElement).className).toBe('node'); expect((node as Node as HTMLElement).className).toBe('node');
expect(((node as Node) as HTMLElement).getAttribute('style')).toBe( expect((node as Node as HTMLElement).getAttribute('style')).toBe(
'color: white', 'color: white',
); );
rrNode.attributes = { id: 'node2' }; rrNode.attributes = { id: 'node2' };
diff(node, rrNode, replayer); diff(node, rrNode, replayer);
expect(((node as Node) as HTMLElement).id).toBe('node2'); expect((node as Node as HTMLElement).id).toBe('node2');
expect(((node as Node) as HTMLElement).className).toBe(''); expect((node as Node as HTMLElement).className).toBe('');
expect(((node as Node) as HTMLElement).getAttribute('style')).toBe(null); expect((node as Node as HTMLElement).getAttribute('style')).toBe(null);
}); });
it('can delete old properties', () => { it('can delete old properties', () => {
@@ -359,9 +361,9 @@ describe('diff algorithm for rrdom', () => {
const sn = Object.assign({}, elementSn, { tagName }); const sn = Object.assign({}, elementSn, { tagName });
mirror.add(node, sn); mirror.add(node, sn);
((node as Node) as HTMLElement).id = 'element1'; (node as Node as HTMLElement).id = 'element1';
((node as Node) as HTMLElement).className = 'element'; (node as Node as HTMLElement).className = 'element';
((node as Node) as HTMLElement).setAttribute('style', 'color: black'); (node as Node as HTMLElement).setAttribute('style', 'color: black');
const rrDocument = new RRDocument(); const rrDocument = new RRDocument();
const rrNode = rrDocument.createElement(tagName); const rrNode = rrDocument.createElement(tagName);
const sn2 = Object.assign({}, elementSn, { tagName }); const sn2 = Object.assign({}, elementSn, { tagName });
@@ -369,15 +371,15 @@ describe('diff algorithm for rrdom', () => {
rrNode.attributes = { id: 'node1' }; rrNode.attributes = { id: 'node1' };
diff(node, rrNode, replayer); diff(node, rrNode, replayer);
expect(((node as Node) as HTMLElement).id).toBe('node1'); expect((node as Node as HTMLElement).id).toBe('node1');
expect(((node as Node) as HTMLElement).className).toBe(''); expect((node as Node as HTMLElement).className).toBe('');
expect(((node as Node) as HTMLElement).getAttribute('style')).toBe(null); expect((node as Node as HTMLElement).getAttribute('style')).toBe(null);
rrNode.attributes = { src: 'link' }; rrNode.attributes = { src: 'link' };
diff(node, rrNode, replayer); diff(node, rrNode, replayer);
expect(((node as Node) as HTMLElement).id).toBe(''); expect((node as Node as HTMLElement).id).toBe('');
expect(((node as Node) as HTMLElement).className).toBe(''); expect((node as Node as HTMLElement).className).toBe('');
expect(((node as Node) as HTMLElement).getAttribute('src')).toBe('link'); expect((node as Node as HTMLElement).getAttribute('src')).toBe('link');
}); });
it('can diff scroll positions', () => { it('can diff scroll positions', () => {
@@ -386,8 +388,8 @@ describe('diff algorithm for rrdom', () => {
const sn = Object.assign({}, elementSn, { tagName }); const sn = Object.assign({}, elementSn, { tagName });
mirror.add(node, sn); mirror.add(node, sn);
expect(((node as Node) as HTMLElement).scrollLeft).toEqual(0); expect((node as Node as HTMLElement).scrollLeft).toEqual(0);
expect(((node as Node) as HTMLElement).scrollTop).toEqual(0); expect((node as Node as HTMLElement).scrollTop).toEqual(0);
const rrDocument = new RRDocument(); const rrDocument = new RRDocument();
const rrNode = rrDocument.createElement(tagName); const rrNode = rrDocument.createElement(tagName);
const sn2 = Object.assign({}, elementSn, { tagName }); const sn2 = Object.assign({}, elementSn, { tagName });
@@ -396,8 +398,8 @@ describe('diff algorithm for rrdom', () => {
rrNode.scrollLeft = 100; rrNode.scrollLeft = 100;
rrNode.scrollTop = 200; rrNode.scrollTop = 200;
diff(node, rrNode, replayer); diff(node, rrNode, replayer);
expect(((node as Node) as HTMLElement).scrollLeft).toEqual(100); expect((node as Node as HTMLElement).scrollLeft).toEqual(100);
expect(((node as Node) as HTMLElement).scrollTop).toEqual(200); expect((node as Node as HTMLElement).scrollTop).toEqual(200);
}); });
it('can diff properties for SVG elements', () => { it('can diff properties for SVG elements', () => {
@@ -412,9 +414,7 @@ describe('diff algorithm for rrdom', () => {
jest.spyOn(Element.prototype, 'setAttributeNS'); jest.spyOn(Element.prototype, 'setAttributeNS');
diff(element, node, replayer); diff(element, node, replayer);
expect(((element as Node) as SVGElement).getAttribute('xmlns')).toBe( expect((element as Node as SVGElement).getAttribute('xmlns')).toBe(value);
value,
);
expect(SVGElement.prototype.setAttributeNS).toHaveBeenCalledWith( expect(SVGElement.prototype.setAttributeNS).toHaveBeenCalledWith(
'http://www.w3.org/2000/xmlns/', 'http://www.w3.org/2000/xmlns/',
'xmlns', 'xmlns',
@@ -464,9 +464,7 @@ describe('diff algorithm for rrdom', () => {
expect(node.childNodes.length).toEqual(3); expect(node.childNodes.length).toEqual(3);
expect(rrNode.childNodes.length).toEqual(3); expect(rrNode.childNodes.length).toEqual(3);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
1, 1, 2, 3,
2,
3,
]); ]);
}); });
@@ -494,11 +492,7 @@ describe('diff algorithm for rrdom', () => {
expect(node.childNodes.length).toEqual(5); expect(node.childNodes.length).toEqual(5);
expect(rrNode.childNodes.length).toEqual(5); expect(rrNode.childNodes.length).toEqual(5);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
1, 1, 2, 3, 4, 5,
2,
3,
4,
5,
]); ]);
}); });
@@ -526,11 +520,7 @@ describe('diff algorithm for rrdom', () => {
expect(node.childNodes.length).toEqual(5); expect(node.childNodes.length).toEqual(5);
expect(rrNode.childNodes.length).toEqual(5); expect(rrNode.childNodes.length).toEqual(5);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
1, 1, 2, 3, 4, 5,
2,
3,
4,
5,
]); ]);
}); });
@@ -558,11 +548,7 @@ describe('diff algorithm for rrdom', () => {
expect(node.childNodes.length).toEqual(5); expect(node.childNodes.length).toEqual(5);
expect(rrNode.childNodes.length).toEqual(5); expect(rrNode.childNodes.length).toEqual(5);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
1, 1, 2, 3, 4, 5,
2,
3,
4,
5,
]); ]);
}); });
@@ -589,9 +575,7 @@ describe('diff algorithm for rrdom', () => {
expect(node.childNodes.length).toEqual(3); expect(node.childNodes.length).toEqual(3);
expect(rrNode.childNodes.length).toEqual(3); expect(rrNode.childNodes.length).toEqual(3);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
1, 1, 2, 3,
2,
3,
]); ]);
}); });
@@ -631,11 +615,7 @@ describe('diff algorithm for rrdom', () => {
) as Node; ) as Node;
expect(node.childNodes.length).toEqual(5); expect(node.childNodes.length).toEqual(5);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
1, 1, 2, 3, 4, 5,
2,
3,
4,
5,
]); ]);
const rrNode = createTree( const rrNode = createTree(
{ {
@@ -650,9 +630,7 @@ describe('diff algorithm for rrdom', () => {
expect(node.childNodes.length).toEqual(3); expect(node.childNodes.length).toEqual(3);
expect(rrNode.childNodes.length).toEqual(3); expect(rrNode.childNodes.length).toEqual(3);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
3, 3, 4, 5,
4,
5,
]); ]);
}); });
@@ -668,11 +646,7 @@ describe('diff algorithm for rrdom', () => {
) as Node; ) as Node;
expect(node.childNodes.length).toEqual(5); expect(node.childNodes.length).toEqual(5);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
1, 1, 2, 3, 4, 5,
2,
3,
4,
5,
]); ]);
const rrNode = createTree( const rrNode = createTree(
{ {
@@ -687,9 +661,7 @@ describe('diff algorithm for rrdom', () => {
expect(node.childNodes.length).toEqual(3); expect(node.childNodes.length).toEqual(3);
expect(rrNode.childNodes.length).toEqual(3); expect(rrNode.childNodes.length).toEqual(3);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
1, 1, 2, 3,
2,
3,
]); ]);
}); });
@@ -705,11 +677,7 @@ describe('diff algorithm for rrdom', () => {
) as Node; ) as Node;
expect(node.childNodes.length).toEqual(5); expect(node.childNodes.length).toEqual(5);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
1, 1, 2, 3, 4, 5,
2,
3,
4,
5,
]); ]);
const rrNode = createTree( const rrNode = createTree(
{ {
@@ -724,10 +692,7 @@ describe('diff algorithm for rrdom', () => {
expect(node.childNodes.length).toEqual(4); expect(node.childNodes.length).toEqual(4);
expect(rrNode.childNodes.length).toEqual(4); expect(rrNode.childNodes.length).toEqual(4);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
1, 1, 2, 4, 5,
2,
4,
5,
]); ]);
}); });
@@ -743,11 +708,7 @@ describe('diff algorithm for rrdom', () => {
) as Node; ) as Node;
expect(node.childNodes.length).toEqual(5); expect(node.childNodes.length).toEqual(5);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
1, 1, 2, 3, 4, 5,
2,
3,
4,
5,
]); ]);
const rrNode = createTree( const rrNode = createTree(
{ {
@@ -762,11 +723,7 @@ describe('diff algorithm for rrdom', () => {
expect(node.childNodes.length).toEqual(5); expect(node.childNodes.length).toEqual(5);
expect(rrNode.childNodes.length).toEqual(5); expect(rrNode.childNodes.length).toEqual(5);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
2, 2, 3, 4, 1, 5,
3,
4,
1,
5,
]); ]);
}); });
@@ -782,9 +739,7 @@ describe('diff algorithm for rrdom', () => {
) as Node; ) as Node;
expect(node.childNodes.length).toEqual(3); expect(node.childNodes.length).toEqual(3);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
1, 1, 2, 3,
2,
3,
]); ]);
const rrNode = createTree( const rrNode = createTree(
{ {
@@ -799,9 +754,7 @@ describe('diff algorithm for rrdom', () => {
expect(node.childNodes.length).toEqual(3); expect(node.childNodes.length).toEqual(3);
expect(rrNode.childNodes.length).toEqual(3); expect(rrNode.childNodes.length).toEqual(3);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
2, 2, 3, 1,
3,
1,
]); ]);
}); });
@@ -829,10 +782,7 @@ describe('diff algorithm for rrdom', () => {
expect(node.childNodes.length).toEqual(4); expect(node.childNodes.length).toEqual(4);
expect(rrNode.childNodes.length).toEqual(4); expect(rrNode.childNodes.length).toEqual(4);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
1, 1, 4, 2, 3,
4,
2,
3,
]); ]);
}); });
@@ -860,10 +810,7 @@ describe('diff algorithm for rrdom', () => {
expect(node.childNodes.length).toEqual(4); expect(node.childNodes.length).toEqual(4);
expect(rrNode.childNodes.length).toEqual(4); expect(rrNode.childNodes.length).toEqual(4);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
4, 4, 2, 3, 1,
2,
3,
1,
]); ]);
}); });
@@ -891,11 +838,7 @@ describe('diff algorithm for rrdom', () => {
expect(node.childNodes.length).toEqual(5); expect(node.childNodes.length).toEqual(5);
expect(rrNode.childNodes.length).toEqual(5); expect(rrNode.childNodes.length).toEqual(5);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
4, 4, 1, 2, 3, 6,
1,
2,
3,
6,
]); ]);
}); });
@@ -923,8 +866,7 @@ describe('diff algorithm for rrdom', () => {
expect(node.childNodes.length).toEqual(2); expect(node.childNodes.length).toEqual(2);
expect(rrNode.childNodes.length).toEqual(2); expect(rrNode.childNodes.length).toEqual(2);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
4, 4, 6,
6,
]); ]);
}); });
@@ -958,14 +900,7 @@ describe('diff algorithm for rrdom', () => {
expect(node.childNodes.length).toEqual(8); expect(node.childNodes.length).toEqual(8);
expect(rrNode.childNodes.length).toEqual(8); expect(rrNode.childNodes.length).toEqual(8);
expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([ expect(Array.from(node.childNodes).map((c) => mirror.getId(c))).toEqual([
8, 8, 7, 6, 5, 4, 3, 2, 1,
7,
6,
5,
4,
3,
2,
1,
]); ]);
}); });
@@ -1131,7 +1066,7 @@ describe('diff algorithm for rrdom', () => {
id: 1, id: 1,
} as serializedNodeWithId); } as serializedNodeWithId);
expect(((node as Node) as HTMLElement).shadowRoot).toBeNull(); expect((node as Node as HTMLElement).shadowRoot).toBeNull();
const rrDocument = new RRDocument(); const rrDocument = new RRDocument();
const rrNode = rrDocument.createElement(tagName); const rrNode = rrDocument.createElement(tagName);
@@ -1147,11 +1082,11 @@ describe('diff algorithm for rrdom', () => {
expect(rrNode.shadowRoot!.childNodes.length).toBe(1); expect(rrNode.shadowRoot!.childNodes.length).toBe(1);
diff(node, rrNode, replayer, rrDocument.mirror); diff(node, rrNode, replayer, rrDocument.mirror);
expect(((node as Node) as HTMLElement).shadowRoot).not.toBeNull(); expect((node as Node as HTMLElement).shadowRoot).not.toBeNull();
expect( expect((node as Node as HTMLElement).shadowRoot!.childNodes.length).toBe(
((node as Node) as HTMLElement).shadowRoot!.childNodes.length, 1,
).toBe(1); );
const childElement = ((node as Node) as HTMLElement).shadowRoot! const childElement = (node as Node as HTMLElement).shadowRoot!
.childNodes[0] as HTMLElement; .childNodes[0] as HTMLElement;
expect(childElement.tagName).toEqual('DIV'); expect(childElement.tagName).toEqual('DIV');
}); });
@@ -1623,7 +1558,7 @@ describe('diff algorithm for rrdom', () => {
let result = createOrGetNode(rrNode, mirror, rrDocument.mirror); let result = createOrGetNode(rrNode, mirror, rrDocument.mirror);
expect(result).toBeInstanceOf(HTMLElement); expect(result).toBeInstanceOf(HTMLElement);
expect(mirror.getId(result)).toBe(0); expect(mirror.getId(result)).toBe(0);
expect(((result as Node) as HTMLElement).tagName).toBe('DIV'); expect((result as Node as HTMLElement).tagName).toBe('DIV');
}); });
it('create a node from RRNode', () => { it('create a node from RRNode', () => {
@@ -1639,14 +1574,14 @@ describe('diff algorithm for rrdom', () => {
result = createOrGetNode(rrNode, mirror, rrDocument.mirror); result = createOrGetNode(rrNode, mirror, rrDocument.mirror);
expect(result).toBeInstanceOf(Text); expect(result).toBeInstanceOf(Text);
expect(mirror.getId(result)).toBe(1); expect(mirror.getId(result)).toBe(1);
expect(((result as Node) as Text).textContent).toBe(textContent); expect((result as Node as Text).textContent).toBe(textContent);
rrNode = rrDocument.createComment(textContent); rrNode = rrDocument.createComment(textContent);
rrDocument.mirror.add(rrNode, getDefaultSN(rrNode, 2)); rrDocument.mirror.add(rrNode, getDefaultSN(rrNode, 2));
result = createOrGetNode(rrNode, mirror, rrDocument.mirror); result = createOrGetNode(rrNode, mirror, rrDocument.mirror);
expect(result).toBeInstanceOf(Comment); expect(result).toBeInstanceOf(Comment);
expect(mirror.getId(result)).toBe(2); expect(mirror.getId(result)).toBe(2);
expect(((result as Node) as Comment).textContent).toBe(textContent); expect((result as Node as Comment).textContent).toBe(textContent);
rrNode = rrDocument.createCDATASection(''); rrNode = rrDocument.createCDATASection('');
rrDocument.mirror.add(rrNode, getDefaultSN(rrNode, 3)); rrDocument.mirror.add(rrNode, getDefaultSN(rrNode, 3));
@@ -1665,9 +1600,9 @@ describe('diff algorithm for rrdom', () => {
let result = createOrGetNode(rrNode, mirror, rrDocument.mirror); let result = createOrGetNode(rrNode, mirror, rrDocument.mirror);
expect(result).toBeInstanceOf(DocumentType); expect(result).toBeInstanceOf(DocumentType);
expect(mirror.getId(result)).toBe(0); expect(mirror.getId(result)).toBe(0);
expect(((result as Node) as DocumentType).name).toEqual('html'); expect((result as Node as DocumentType).name).toEqual('html');
expect(((result as Node) as DocumentType).publicId).toEqual(publicId); expect((result as Node as DocumentType).publicId).toEqual(publicId);
expect(((result as Node) as DocumentType).systemId).toEqual(''); expect((result as Node as DocumentType).systemId).toEqual('');
}); });
it('can get a node if it already exists', () => { it('can get a node if it already exists', () => {
@@ -1687,7 +1622,7 @@ describe('diff algorithm for rrdom', () => {
expect(result).toBeInstanceOf(Text); expect(result).toBeInstanceOf(Text);
expect(mirror.getId(result)).toBe(0); expect(mirror.getId(result)).toBe(0);
expect(((result as Node) as Text).textContent).toBe(textContent); expect((result as Node as Text).textContent).toBe(textContent);
expect(result).toEqual(text); expect(result).toEqual(text);
// To make sure the existed text node is used. // To make sure the existed text node is used.
expect(mirror.getMeta(result)).toEqual(mirror.getMeta(text)); expect(mirror.getMeta(result)).toEqual(mirror.getMeta(text));
@@ -1696,7 +1631,7 @@ describe('diff algorithm for rrdom', () => {
describe('apply virtual style rules to node', () => { describe('apply virtual style rules to node', () => {
beforeEach(() => { beforeEach(() => {
const dummyReplayer = new Replayer(([ const dummyReplayer = new Replayer([
{ {
type: EventType.DomContentLoaded, type: EventType.DomContentLoaded,
timestamp: 0, timestamp: 0,
@@ -1709,7 +1644,7 @@ describe('diff algorithm for rrdom', () => {
}, },
timestamp: 0, timestamp: 0,
}, },
] as unknown) as eventWithTime[]); ] as unknown as eventWithTime[]);
replayer.applyStyleSheetMutation = ( replayer.applyStyleSheetMutation = (
data: styleDeclarationData | styleSheetRuleData, data: styleDeclarationData | styleSheetRuleData,
styleSheet: CSSStyleSheet, styleSheet: CSSStyleSheet,

View File

@@ -424,7 +424,7 @@ describe('Basic RRDocument implementation', () => {
expect(node.removeAttribute).toBeDefined(); expect(node.removeAttribute).toBeDefined();
expect(node.attachShadow).toBeDefined(); expect(node.attachShadow).toBeDefined();
expect(node.dispatchEvent).toBeDefined(); expect(node.dispatchEvent).toBeDefined();
expect(node.dispatchEvent((null as unknown) as Event)).toBeTruthy(); expect(node.dispatchEvent(null as unknown as Event)).toBeTruthy();
expect(node.toString()).toEqual('DIV id="id" class="className" '); expect(node.toString()).toEqual('DIV id="id" class="className" ');
}); });

View File

@@ -1,7 +1,7 @@
import * as rollup from 'rollup'; import * as rollup from 'rollup';
import * as typescript from 'rollup-plugin-typescript2'; import * as typescript from 'rollup-plugin-typescript2';
import resolve from '@rollup/plugin-node-resolve'; import resolve from '@rollup/plugin-node-resolve';
const _typescript = (typescript as unknown) as typeof typescript.default; const _typescript = typescript as unknown as typeof typescript.default;
/** /**
* Use rollup to compile an input TS script into JS code string. * Use rollup to compile an input TS script into JS code string.
@@ -10,10 +10,10 @@ export async function compileTSCode(inputFilePath: string) {
const bundle = await rollup.rollup({ const bundle = await rollup.rollup({
input: inputFilePath, input: inputFilePath,
plugins: [ plugins: [
(resolve() as unknown) as rollup.Plugin, resolve() as unknown as rollup.Plugin,
(_typescript({ _typescript({
tsconfigOverride: { compilerOptions: { module: 'ESNext' } }, tsconfigOverride: { compilerOptions: { module: 'ESNext' } },
}) as unknown) as rollup.Plugin, }) as unknown as rollup.Plugin,
], ],
}); });
const { const {

View File

@@ -98,7 +98,7 @@ describe('RRDocument for browser environment', () => {
// build from element // build from element
expect(mirror.getMeta(document.documentElement)).toBeNull(); expect(mirror.getMeta(document.documentElement)).toBeNull();
rrNode = buildFromNode( rrNode = buildFromNode(
(document.documentElement as unknown) as Node, document.documentElement as unknown as Node,
rrdom, rrdom,
mirror, mirror,
)!; )!;
@@ -378,7 +378,7 @@ describe('RRDocument for browser environment', () => {
expect(dom.mirror.getId(node1)).toEqual(0); expect(dom.mirror.getId(node1)).toEqual(0);
const node2 = dom.createTextNode('text'); const node2 = dom.createTextNode('text');
expect(dom.mirror.getId(node2)).toEqual(-1); expect(dom.mirror.getId(node2)).toEqual(-1);
expect(dom.mirror.getId((null as unknown) as RRNode)).toEqual(-1); expect(dom.mirror.getId(null as unknown as RRNode)).toEqual(-1);
}); });
it('has() should return whether the mirror has an ID', () => { it('has() should return whether the mirror has an ID', () => {

View File

@@ -267,8 +267,8 @@ function buildNode(
rr_dataURL: string; rr_dataURL: string;
}; };
// If the canvas element is created in RRDom runtime (seeking to a time point), the canvas context isn't supported. So the data has to be stored and not handled until diff process. https://github.com/rrweb-io/rrweb/pull/944 // If the canvas element is created in RRDom runtime (seeking to a time point), the canvas context isn't supported. So the data has to be stored and not handled until diff process. https://github.com/rrweb-io/rrweb/pull/944
if (((node as unknown) as RRCanvasElement).RRNodeType) if ((node as unknown as RRCanvasElement).RRNodeType)
((node as unknown) as RRCanvasElement).rr_dataURL = value.toString(); (node as unknown as RRCanvasElement).rr_dataURL = value.toString();
} else if (tagName === 'img' && name === 'rr_dataURL') { } else if (tagName === 'img' && name === 'rr_dataURL') {
const image = node as HTMLImageElement; const image = node as HTMLImageElement;
if (!image.currentSrc.startsWith('data:')) { if (!image.currentSrc.startsWith('data:')) {

View File

@@ -110,7 +110,7 @@ export class Mirror implements IMirror<Node> {
if (n.childNodes) { if (n.childNodes) {
n.childNodes.forEach((childNode) => n.childNodes.forEach((childNode) =>
this.removeNodeFromMap((childNode as unknown) as Node), this.removeNodeFromMap(childNode as unknown as Node),
); );
} }
} }

View File

@@ -8,7 +8,7 @@ import * as typescript from 'rollup-plugin-typescript2';
import * as assert from 'assert'; import * as assert from 'assert';
import { waitForRAF } from './utils'; import { waitForRAF } from './utils';
const _typescript = (typescript as unknown) as () => rollup.Plugin; const _typescript = typescript as unknown as () => rollup.Plugin;
const htmlFolder = path.join(__dirname, 'html'); const htmlFolder = path.join(__dirname, 'html');
const htmls = fs.readdirSync(htmlFolder).map((filePath) => { const htmls = fs.readdirSync(htmlFolder).map((filePath) => {
@@ -129,7 +129,8 @@ describe('integration tests', function (this: ISuite) {
}); });
} }
await waitForRAF(page); await waitForRAF(page);
const rebuildHtml = ((await page.evaluate(`${code} const rebuildHtml = (
(await page.evaluate(`${code}
const x = new XMLSerializer(); const x = new XMLSerializer();
const snap = rrweb.snapshot(document); const snap = rrweb.snapshot(document);
let out = x.serializeToString(rrweb.rebuild(snap, { doc: document })); let out = x.serializeToString(rrweb.rebuild(snap, { doc: document }));
@@ -138,7 +139,8 @@ describe('integration tests', function (this: ISuite) {
out = out.replace(' xmlns=\"http://www.w3.org/1999/xhtml\"', ''); out = out.replace(' xmlns=\"http://www.w3.org/1999/xhtml\"', '');
} }
out; // return out; // return
`)) as string) `)) as string
)
.replace(/\n\n/g, '') .replace(/\n\n/g, '')
.replace( .replace(
/blob:http:\/\/localhost:\d+\/[0-9a-z\-]+/, /blob:http:\/\/localhost:\d+\/[0-9a-z\-]+/,

View File

@@ -90,9 +90,9 @@ function initLogObserver(
win: IWindow, // top window or in an iframe win: IWindow, // top window or in an iframe
options: LogRecordOptions, options: LogRecordOptions,
): listenerHandler { ): listenerHandler {
const logOptions = (options const logOptions = (
? Object.assign({}, defaultLogOptions, options) options ? Object.assign({}, defaultLogOptions, options) : defaultLogOptions
: defaultLogOptions) as { ) as {
level: LogLevel[]; level: LogLevel[];
lengthThreshold: number; lengthThreshold: number;
stringifyOptions?: StringifyOptions; stringifyOptions?: StringifyOptions;
@@ -117,9 +117,9 @@ function initLogObserver(
const errorHandler = (event: ErrorEvent) => { const errorHandler = (event: ErrorEvent) => {
const message = event.message, const message = event.message,
error = event.error as Error; error = event.error as Error;
const trace: string[] = ErrorStackParser.parse( const trace: string[] = ErrorStackParser.parse(error).map(
error, (stackFrame: StackFrame) => stackFrame.toString(),
).map((stackFrame: StackFrame) => stackFrame.toString()); );
const payload = [stringify(message, logOptions.stringifyOptions)]; const payload = [stringify(message, logOptions.stringifyOptions)];
cb({ cb({
level: 'error', level: 'error',
@@ -149,9 +149,9 @@ function initLogObserver(
stringify(event.reason, logOptions.stringifyOptions), stringify(event.reason, logOptions.stringifyOptions),
]; ];
} }
const trace: string[] = ErrorStackParser.parse( const trace: string[] = ErrorStackParser.parse(error).map(
error, (stackFrame: StackFrame) => stackFrame.toString(),
).map((stackFrame: StackFrame) => stackFrame.toString()); );
cb({ cb({
level: 'error', level: 'error',
trace, trace,

View File

@@ -123,7 +123,7 @@ export function stringify(
if (value instanceof Event) { if (value instanceof Event) {
const eventResult: Record<string, unknown> = {}; const eventResult: Record<string, unknown> = {};
for (const eventKey in value) { for (const eventKey in value) {
const eventValue = ((value as unknown) as Record<string, unknown>)[ const eventValue = (value as unknown as Record<string, unknown>)[
eventKey eventKey
]; ];
if (Array.isArray(eventValue)) { if (Array.isArray(eventValue)) {

View File

@@ -59,10 +59,10 @@ class LogReplayPlugin {
for (const level of this.config.level!) { for (const level of this.config.level!) {
if (level === 'trace') { if (level === 'trace') {
replayLogger[level] = (data: LogData) => { replayLogger[level] = (data: LogData) => {
const logger = ((console.log as unknown) as PatchedConsoleLog)[ const logger = (console.log as unknown as PatchedConsoleLog)[
ORIGINAL_ATTRIBUTE_NAME ORIGINAL_ATTRIBUTE_NAME
] ]
? ((console.log as unknown) as PatchedConsoleLog)[ ? (console.log as unknown as PatchedConsoleLog)[
ORIGINAL_ATTRIBUTE_NAME ORIGINAL_ATTRIBUTE_NAME
] ]
: console.log; : console.log;
@@ -73,10 +73,10 @@ class LogReplayPlugin {
}; };
} else { } else {
replayLogger[level] = (data: LogData) => { replayLogger[level] = (data: LogData) => {
const logger = ((console[level] as unknown) as PatchedConsoleLog)[ const logger = (console[level] as unknown as PatchedConsoleLog)[
ORIGINAL_ATTRIBUTE_NAME ORIGINAL_ATTRIBUTE_NAME
] ]
? ((console[level] as unknown) as PatchedConsoleLog)[ ? (console[level] as unknown as PatchedConsoleLog)[
ORIGINAL_ATTRIBUTE_NAME ORIGINAL_ATTRIBUTE_NAME
] ]
: console[level]; : console[level];
@@ -118,7 +118,7 @@ export const getReplayConsolePlugin: (
event.type === EventType.IncrementalSnapshot && event.type === EventType.IncrementalSnapshot &&
event.data.source === (IncrementalSource.Log as IncrementalSource) event.data.source === (IncrementalSource.Log as IncrementalSource)
) { ) {
logData = (event.data as unknown) as LogData; logData = event.data as unknown as LogData;
} else if ( } else if (
event.type === EventType.Plugin && event.type === EventType.Plugin &&
event.data.plugin === PLUGIN_NAME event.data.plugin === PLUGIN_NAME

View File

@@ -22,7 +22,7 @@ export const getReplaySequentialIdPlugin: (
return { return {
handler(event: eventWithTime) { handler(event: eventWithTime) {
if (key in event) { if (key in event) {
const id = ((event as unknown) as Record<string, number>)[key]; const id = (event as unknown as Record<string, number>)[key];
if (id !== currentId) { if (id !== currentId) {
console.error( console.error(
`[sequential-id-plugin]: expect to get an id with value "${currentId}", but got "${id}"`, `[sequential-id-plugin]: expect to get an id with value "${currentId}", but got "${id}"`,

View File

@@ -1,6 +1,7 @@
import type { ICrossOriginIframeMirror } from '@rrweb/types'; import type { ICrossOriginIframeMirror } from '@rrweb/types';
export default class CrossOriginIframeMirror export default class CrossOriginIframeMirror
implements ICrossOriginIframeMirror { implements ICrossOriginIframeMirror
{
private iframeIdToRemoteIdMap: WeakMap< private iframeIdToRemoteIdMap: WeakMap<
HTMLIFrameElement, HTMLIFrameElement,
Map<number, number> Map<number, number>

View File

@@ -8,16 +8,12 @@ import type { StylesheetManager } from './stylesheet-manager';
export class IframeManager { export class IframeManager {
private iframes: WeakMap<HTMLIFrameElement, true> = new WeakMap(); private iframes: WeakMap<HTMLIFrameElement, true> = new WeakMap();
private crossOriginIframeMap: WeakMap< private crossOriginIframeMap: WeakMap<MessageEventSource, HTMLIFrameElement> =
MessageEventSource, new WeakMap();
HTMLIFrameElement
> = new WeakMap();
public crossOriginIframeMirror = new CrossOriginIframeMirror(genId); public crossOriginIframeMirror = new CrossOriginIframeMirror(genId);
public crossOriginIframeStyleMirror: CrossOriginIframeMirror; public crossOriginIframeStyleMirror: CrossOriginIframeMirror;
public crossOriginIframeRootIdMap: WeakMap< public crossOriginIframeRootIdMap: WeakMap<HTMLIFrameElement, number> =
HTMLIFrameElement, new WeakMap();
number
> = new WeakMap();
private mirror: Mirror; private mirror: Mirror;
private mutationCb: mutationCallBack; private mutationCb: mutationCallBack;
private wrappedEmit: (e: eventWithTime, isCheckout?: boolean) => void; private wrappedEmit: (e: eventWithTime, isCheckout?: boolean) => void;

View File

@@ -173,9 +173,9 @@ function record<T = eventWithTime>(
// Disable packing events which will be emitted to parent frames. // Disable packing events which will be emitted to parent frames.
!passEmitsToParent !passEmitsToParent
) { ) {
e = (packFn(e) as unknown) as eventWithTime; e = packFn(e) as unknown as eventWithTime;
} }
return (e as unknown) as T; return e as unknown as T;
}; };
wrappedEmit = (e: eventWithTime, isCheckout?: boolean) => { wrappedEmit = (e: eventWithTime, isCheckout?: boolean) => {
if ( if (

View File

@@ -180,29 +180,31 @@ export default class MutationBuffer {
private processedNodeManager: observerParam['processedNodeManager']; private processedNodeManager: observerParam['processedNodeManager'];
public init(options: MutationBufferParam) { public init(options: MutationBufferParam) {
([ (
'mutationCb', [
'blockClass', 'mutationCb',
'blockSelector', 'blockClass',
'maskTextClass', 'blockSelector',
'maskTextSelector', 'maskTextClass',
'inlineStylesheet', 'maskTextSelector',
'maskInputOptions', 'inlineStylesheet',
'maskTextFn', 'maskInputOptions',
'maskInputFn', 'maskTextFn',
'keepIframeSrcFn', 'maskInputFn',
'recordCanvas', 'keepIframeSrcFn',
'inlineImages', 'recordCanvas',
'slimDOMOptions', 'inlineImages',
'dataURLOptions', 'slimDOMOptions',
'doc', 'dataURLOptions',
'mirror', 'doc',
'iframeManager', 'mirror',
'stylesheetManager', 'iframeManager',
'shadowDomManager', 'stylesheetManager',
'canvasManager', 'shadowDomManager',
'processedNodeManager', 'canvasManager',
] as const).forEach((key) => { 'processedNodeManager',
] as const
).forEach((key) => {
// just a type trick, the runtime result is correct // just a type trick, the runtime result is correct
this[key] = options[key] as never; this[key] = options[key] as never;
}); });

View File

@@ -94,19 +94,18 @@ export function initMutationObserver(
* window.__rrMutationObserver = MutationObserver * window.__rrMutationObserver = MutationObserver
*/ */
(window as WindowWithStoredMutationObserver).__rrMutationObserver; (window as WindowWithStoredMutationObserver).__rrMutationObserver;
const angularZoneSymbol = (window as WindowWithAngularZone)?.Zone?.__symbol__?.( const angularZoneSymbol = (
'MutationObserver', window as WindowWithAngularZone
); )?.Zone?.__symbol__?.('MutationObserver');
if ( if (
angularZoneSymbol && angularZoneSymbol &&
((window as unknown) as Record<string, typeof MutationObserver>)[ (window as unknown as Record<string, typeof MutationObserver>)[
angularZoneSymbol angularZoneSymbol
] ]
) { ) {
mutationObserverCtor = ((window as unknown) as Record< mutationObserverCtor = (
string, window as unknown as Record<string, typeof MutationObserver>
typeof MutationObserver )[angularZoneSymbol];
>)[angularZoneSymbol];
} }
const observer = new (mutationObserverCtor as new ( const observer = new (mutationObserverCtor as new (
callback: MutationCallback, callback: MutationCallback,
@@ -423,9 +422,9 @@ function initInputObserver({
} }
} }
const events = sampling.input === 'last' ? ['change'] : ['input', 'change']; const events = sampling.input === 'last' ? ['change'] : ['input', 'change'];
const handlers: Array< const handlers: Array<listenerHandler | hookResetter> = events.map(
listenerHandler | hookResetter (eventName) => on(eventName, eventHandler, doc),
> = events.map((eventName) => on(eventName, eventHandler, doc)); );
const currentWindow = doc.defaultView; const currentWindow = doc.defaultView;
if (!currentWindow) { if (!currentWindow) {
return () => { return () => {
@@ -891,12 +890,8 @@ function initMediaInteractionObserver({
) { ) {
return; return;
} }
const { const { currentTime, volume, muted, playbackRate } =
currentTime, target as HTMLMediaElement;
volume,
muted,
playbackRate,
} = target as HTMLMediaElement;
mediaInteractionCb({ mediaInteractionCb({
type, type,
id: mirror.getId(target as Node), id: mirror.getId(target as Node),
@@ -931,7 +926,7 @@ function initFontObserver({ fontCb, doc }: observerParam): listenerHandler {
const fontMap = new WeakMap<FontFace, fontParam>(); const fontMap = new WeakMap<FontFace, fontParam>();
const originalFontFace = win.FontFace; const originalFontFace = win.FontFace;
win.FontFace = (function FontFace( win.FontFace = function FontFace(
family: string, family: string,
source: string | ArrayBufferLike, source: string | ArrayBufferLike,
descriptors?: FontFaceDescriptors, descriptors?: FontFaceDescriptors,
@@ -947,7 +942,7 @@ function initFontObserver({ fontCb, doc }: observerParam): listenerHandler {
: JSON.stringify(Array.from(new Uint8Array(source))), : JSON.stringify(Array.from(new Uint8Array(source))),
}); });
return fontFace; return fontFace;
} as unknown) as typeof FontFace; } as unknown as typeof FontFace;
const restoreHandler = patch( const restoreHandler = patch(
doc.fonts, doc.fonts,

View File

@@ -116,7 +116,8 @@ export class CanvasManager {
blockSelector, blockSelector,
); );
const snapshotInProgressMap: Map<number, boolean> = new Map(); const snapshotInProgressMap: Map<number, boolean> = new Map();
const worker = new ImageBitmapDataURLWorker() as ImageBitmapDataURLRequestWorker; const worker =
new ImageBitmapDataURLWorker() as ImageBitmapDataURLRequestWorker;
worker.onmessage = (e) => { worker.onmessage = (e) => {
const { id } = e.data; const { id } = e.data;
snapshotInProgressMap.set(id, false); snapshotInProgressMap.set(id, false);

View File

@@ -81,7 +81,7 @@ export class ShadowDomManager {
scrollCb: this.scrollCb, scrollCb: this.scrollCb,
// https://gist.github.com/praveenpuglia/0832da687ed5a5d7a0907046c9ef1813 // https://gist.github.com/praveenpuglia/0832da687ed5a5d7a0907046c9ef1813
// scroll is not allowed to pass the boundary, so we need to listen the shadow document // scroll is not allowed to pass the boundary, so we need to listen the shadow document
doc: (shadowRoot as unknown) as Document, doc: shadowRoot as unknown as Document,
mirror: this.mirror, mirror: this.mirror,
}); });
// Defer this to avoid adoptedStyleSheet events being created before the full snapshot is created or attachShadow action is recorded. // Defer this to avoid adoptedStyleSheet events being created before the full snapshot is created or attachShadow action is recorded.
@@ -113,9 +113,11 @@ export class ShadowDomManager {
const manager = this; const manager = this;
this.restorePatches.push( this.restorePatches.push(
patch( patch(
(iframeElement.contentWindow as Window & { (
HTMLElement: { prototype: HTMLElement }; iframeElement.contentWindow as Window & {
}).HTMLElement.prototype, HTMLElement: { prototype: HTMLElement };
}
).HTMLElement.prototype,
'attachShadow', 'attachShadow',
function (original: (init: ShadowRootInit) => ShadowRoot) { function (original: (init: ShadowRootInit) => ShadowRoot) {
return function (this: HTMLElement, option: ShadowRootInit) { return function (this: HTMLElement, option: ShadowRootInit) {

View File

@@ -20,7 +20,7 @@ export default async function canvasMutation({
if (mutation.setter) { if (mutation.setter) {
// skip some read-only type checks // skip some read-only type checks
((ctx as unknown) as Record<string, unknown>)[mutation.property] = (ctx as unknown as Record<string, unknown>)[mutation.property] =
mutation.args[0]; mutation.args[0];
return; return;
} }

View File

@@ -434,9 +434,10 @@ export class Replayer {
public getMetaData(): playerMetaData { public getMetaData(): playerMetaData {
const firstEvent = this.service.state.context.events[0]; const firstEvent = this.service.state.context.events[0];
const lastEvent = this.service.state.context.events[ const lastEvent =
this.service.state.context.events.length - 1 this.service.state.context.events[
]; this.service.state.context.events.length - 1
];
return { return {
startTime: firstEvent.timestamp, startTime: firstEvent.timestamp,
endTime: lastEvent.timestamp, endTime: lastEvent.timestamp,
@@ -855,7 +856,7 @@ export class Replayer {
const collected: AppendedIframe[] = []; const collected: AppendedIframe[] = [];
const afterAppend = (builtNode: Node, id: number) => { const afterAppend = (builtNode: Node, id: number) => {
this.collectIframeAndAttachDocument(collected, builtNode); this.collectIframeAndAttachDocument(collected, builtNode);
const sn = (mirror as TMirror).getMeta((builtNode as unknown) as TNode); const sn = (mirror as TMirror).getMeta(builtNode as unknown as TNode);
if ( if (
sn?.type === NodeType.Element && sn?.type === NodeType.Element &&
sn?.tagName.toUpperCase() === 'HTML' sn?.tagName.toUpperCase() === 'HTML'
@@ -1263,9 +1264,9 @@ export class Replayer {
if (this.usingVirtualDom) { if (this.usingVirtualDom) {
if (d.styleId) this.constructedStyleMutations.push(d); if (d.styleId) this.constructedStyleMutations.push(d);
else if (d.id) else if (d.id)
(this.virtualDom.mirror.getNode( (
d.id, this.virtualDom.mirror.getNode(d.id) as RRStyleElement | null
) as RRStyleElement | null)?.rules.push(d); )?.rules.push(d);
} else this.applyStyleSheetMutation(d); } else this.applyStyleSheetMutation(d);
break; break;
} }
@@ -1916,10 +1917,10 @@ export class Replayer {
styleSheet: CSSStyleSheet, styleSheet: CSSStyleSheet,
) { ) {
if (data.set) { if (data.set) {
const rule = (getNestedRule( const rule = getNestedRule(
styleSheet.rules, styleSheet.rules,
data.index, data.index,
) as unknown) as CSSStyleRule; ) as unknown as CSSStyleRule;
rule.style.setProperty( rule.style.setProperty(
data.set.property, data.set.property,
data.set.value, data.set.value,
@@ -1928,10 +1929,10 @@ export class Replayer {
} }
if (data.remove) { if (data.remove) {
const rule = (getNestedRule( const rule = getNestedRule(
styleSheet.rules, styleSheet.rules,
data.index, data.index,
) as unknown) as CSSStyleRule; ) as unknown as CSSStyleRule;
rule.style.removeProperty(data.remove.property); rule.style.removeProperty(data.remove.property);
} }
} }
@@ -1977,7 +1978,8 @@ export class Replayer {
.filter((style) => style !== null) as CSSStyleSheet[]; .filter((style) => style !== null) as CSSStyleSheet[];
if (hasShadowRoot(targetHost)) if (hasShadowRoot(targetHost))
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
(targetHost as HTMLElement).shadowRoot!.adoptedStyleSheets = stylesToAdopt; (targetHost as HTMLElement).shadowRoot!.adoptedStyleSheets =
stylesToAdopt;
else if (targetHost.nodeName === '#document') else if (targetHost.nodeName === '#document')
(targetHost as Document).adoptedStyleSheets = stylesToAdopt; (targetHost as Document).adoptedStyleSheets = stylesToAdopt;

View File

@@ -209,4 +209,5 @@ export type CrossOriginIframeMessageEventContent<T = eventWithTime> = {
origin: string; origin: string;
isCheckout?: boolean; isCheckout?: boolean;
}; };
export type CrossOriginIframeMessageEvent = MessageEvent<CrossOriginIframeMessageEventContent>; export type CrossOriginIframeMessageEvent =
MessageEvent<CrossOriginIframeMessageEventContent>;

View File

@@ -281,14 +281,14 @@ export function isTouchEvent(
export function polyfill(win = window) { export function polyfill(win = window) {
if ('NodeList' in win && !win.NodeList.prototype.forEach) { if ('NodeList' in win && !win.NodeList.prototype.forEach) {
// eslint-disable-next-line @typescript-eslint/unbound-method // eslint-disable-next-line @typescript-eslint/unbound-method
win.NodeList.prototype.forEach = (Array.prototype win.NodeList.prototype.forEach = Array.prototype
.forEach as unknown) as NodeList['forEach']; .forEach as unknown as NodeList['forEach'];
} }
if ('DOMTokenList' in win && !win.DOMTokenList.prototype.forEach) { if ('DOMTokenList' in win && !win.DOMTokenList.prototype.forEach) {
// eslint-disable-next-line @typescript-eslint/unbound-method // eslint-disable-next-line @typescript-eslint/unbound-method
win.DOMTokenList.prototype.forEach = (Array.prototype win.DOMTokenList.prototype.forEach = Array.prototype
.forEach as unknown) as DOMTokenList['forEach']; .forEach as unknown as DOMTokenList['forEach'];
} }
// https://github.com/Financial-Times/polyfill-service/pull/183 // https://github.com/Financial-Times/polyfill-service/pull/183
@@ -433,7 +433,7 @@ export function getBaseDimension(
export function hasShadowRoot<T extends Node | RRNode>( export function hasShadowRoot<T extends Node | RRNode>(
n: T, n: T,
): n is T & { shadowRoot: ShadowRoot } { ): n is T & { shadowRoot: ShadowRoot } {
return Boolean(((n as unknown) as Element)?.shadowRoot); return Boolean((n as unknown as Element)?.shadowRoot);
} }
export function getNestedRule( export function getNestedRule(

View File

@@ -147,8 +147,7 @@ const events: eventWithTime[] = [
id: 101, id: 101,
adds: [ adds: [
{ {
rule: rule: '.css-added-at-500-overwritten-at-3000 {border: 1px solid blue;}',
'.css-added-at-500-overwritten-at-3000 {border: 1px solid blue;}',
index: 1, index: 1,
}, },
], ],
@@ -163,8 +162,7 @@ const events: eventWithTime[] = [
id: 105, id: 105,
adds: [ adds: [
{ {
rule: rule: '.css-added-at-1000-deleted-at-2500{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;min-width:60rem;min-height:100vh;color:blue;}',
'.css-added-at-1000-deleted-at-2500{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;min-width:60rem;min-height:100vh;color:blue;}',
index: 2, index: 2,
}, },
], ],

View File

@@ -502,7 +502,8 @@ describe('record integration tests', function (this: ISuite) {
await page.goto('about:blank'); await page.goto('about:blank');
await page.setContent( await page.setContent(
getHtml('log.html', { getHtml('log.html', {
plugins: ('[rrwebConsoleRecord.getRecordConsolePlugin()]' as unknown) as RecordPlugin<unknown>[], plugins:
'[rrwebConsoleRecord.getRecordConsolePlugin()]' as unknown as RecordPlugin<unknown>[],
}), }),
); );
@@ -790,8 +791,8 @@ describe('record integration tests', function (this: ISuite) {
await page.evaluate(() => { await page.evaluate(() => {
// get contentDocument of iframe five // get contentDocument of iframe five
const contentDocument1 = document.querySelector('iframe')! const contentDocument1 =
.contentDocument!; document.querySelector('iframe')!.contentDocument!;
// create shadow dom #1 // create shadow dom #1
contentDocument1.body.attachShadow({ mode: 'open' }); contentDocument1.body.attachShadow({ mode: 'open' });
contentDocument1.body.shadowRoot!.appendChild( contentDocument1.body.shadowRoot!.appendChild(

View File

@@ -17,7 +17,7 @@ describe('pack', () => {
describe('unpack', () => { describe('unpack', () => {
it('is compatible with unpacked data 1', () => { it('is compatible with unpacked data 1', () => {
const result = unpack((event as unknown) as string); const result = unpack(event as unknown as string);
expect(result).toEqual(event); expect(result).toEqual(event);
}); });

View File

@@ -96,9 +96,9 @@ describe('record', function (this: ISuite) {
it('will only have one full snapshot without checkout config', async () => { it('will only have one full snapshot without checkout config', async () => {
await ctx.page.evaluate(() => { await ctx.page.evaluate(() => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
}); });
}); });
let count = 30; let count = 30;
@@ -120,9 +120,9 @@ describe('record', function (this: ISuite) {
it('can checkout full snapshot by count', async () => { it('can checkout full snapshot by count', async () => {
await ctx.page.evaluate(() => { await ctx.page.evaluate(() => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
checkoutEveryNth: 10, checkoutEveryNth: 10,
}); });
}); });
@@ -149,9 +149,9 @@ describe('record', function (this: ISuite) {
it('can checkout full snapshot by time', async () => { it('can checkout full snapshot by time', async () => {
await ctx.page.evaluate(() => { await ctx.page.evaluate(() => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
checkoutEveryNms: 500, checkoutEveryNms: 500,
}); });
}); });
@@ -182,9 +182,9 @@ describe('record', function (this: ISuite) {
it('is safe to checkout during async callbacks', async () => { it('is safe to checkout during async callbacks', async () => {
await ctx.page.evaluate(() => { await ctx.page.evaluate(() => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
checkoutEveryNth: 2, checkoutEveryNth: 2,
}); });
const p = document.createElement('p'); const p = document.createElement('p');
@@ -208,9 +208,9 @@ describe('record', function (this: ISuite) {
it('should record scroll position', async () => { it('should record scroll position', async () => {
await ctx.page.evaluate(() => { await ctx.page.evaluate(() => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
}); });
const p = document.createElement('p'); const p = document.createElement('p');
p.innerText = 'testtesttesttesttesttesttesttesttesttest'; p.innerText = 'testtesttesttesttesttesttesttesttesttest';
@@ -225,9 +225,9 @@ describe('record', function (this: ISuite) {
it('should record selection event', async () => { it('should record selection event', async () => {
await ctx.page.evaluate(() => { await ctx.page.evaluate(() => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
}); });
const startNode = document.createElement('p'); const startNode = document.createElement('p');
@@ -266,9 +266,9 @@ describe('record', function (this: ISuite) {
it('can add custom event', async () => { it('can add custom event', async () => {
await ctx.page.evaluate(() => { await ctx.page.evaluate(() => {
const { record, addCustomEvent } = ((window as unknown) as IWindow).rrweb; const { record, addCustomEvent } = (window as unknown as IWindow).rrweb;
record({ record({
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
}); });
addCustomEvent<number>('tag1', 1); addCustomEvent<number>('tag1', 1);
addCustomEvent<{ a: string }>('tag2', { addCustomEvent<{ a: string }>('tag2', {
@@ -281,10 +281,10 @@ describe('record', function (this: ISuite) {
it('captures stylesheet rules', async () => { it('captures stylesheet rules', async () => {
await ctx.page.evaluate(() => { await ctx.page.evaluate(() => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
}); });
const styleElement = document.createElement('style'); const styleElement = document.createElement('style');
@@ -331,10 +331,10 @@ describe('record', function (this: ISuite) {
const captureNestedStylesheetRulesTest = async () => { const captureNestedStylesheetRulesTest = async () => {
await ctx.page.evaluate(() => { await ctx.page.evaluate(() => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
}); });
const styleElement = document.createElement('style'); const styleElement = document.createElement('style');
@@ -392,10 +392,10 @@ describe('record', function (this: ISuite) {
it('captures style property changes', async () => { it('captures style property changes', async () => {
await ctx.page.evaluate(() => { await ctx.page.evaluate(() => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
ignoreCSSAttributes: new Set(['color']), ignoreCSSAttributes: new Set(['color']),
}); });
@@ -428,7 +428,7 @@ describe('record', function (this: ISuite) {
it('captures inserted style text nodes correctly', async () => { it('captures inserted style text nodes correctly', async () => {
await ctx.page.evaluate(() => { await ctx.page.evaluate(() => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
const styleEl = document.createElement(`style`); const styleEl = document.createElement(`style`);
styleEl.append(document.createTextNode('div { color: red; }')); styleEl.append(document.createTextNode('div { color: red; }'));
@@ -436,7 +436,7 @@ describe('record', function (this: ISuite) {
document.head.appendChild(styleEl); document.head.appendChild(styleEl);
record({ record({
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
}); });
styleEl.append(document.createTextNode('span { color: orange; }')); styleEl.append(document.createTextNode('span { color: orange; }'));
@@ -462,11 +462,11 @@ describe('record', function (this: ISuite) {
}); });
await waitForRAF(ctx.page); await waitForRAF(ctx.page);
await ctx.page.evaluate(() => { await ctx.page.evaluate(() => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
inlineStylesheet: true, inlineStylesheet: true,
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
}); });
}); });
await waitForRAF(ctx.page); await waitForRAF(ctx.page);
@@ -487,14 +487,15 @@ describe('record', function (this: ISuite) {
document.adoptedStyleSheets = [sheet]; document.adoptedStyleSheets = [sheet];
const iframe = document.querySelector('iframe'); const iframe = document.querySelector('iframe');
const sheet2 = new (iframe!.contentWindow! as Window & const sheet2 = new (
typeof globalThis).CSSStyleSheet(); iframe!.contentWindow! as Window & typeof globalThis
).CSSStyleSheet();
// Add stylesheet to an IFrame document. // Add stylesheet to an IFrame document.
iframe!.contentDocument!.adoptedStyleSheets = [sheet2]; iframe!.contentDocument!.adoptedStyleSheets = [sheet2];
iframe!.contentDocument!.body.innerHTML = '<h1>h1 in iframe</h1>'; iframe!.contentDocument!.body.innerHTML = '<h1>h1 in iframe</h1>';
const { rrweb, emit } = (window as unknown) as IWindow; const { rrweb, emit } = window as unknown as IWindow;
rrweb.record({ rrweb.record({
emit, emit,
}); });
@@ -568,7 +569,7 @@ describe('record', function (this: ISuite) {
sheet2.replaceSync!('div {font-size: large;}'); sheet2.replaceSync!('div {font-size: large;}');
shadowHost.shadowRoot!.adoptedStyleSheets = [sheet2]; shadowHost.shadowRoot!.adoptedStyleSheets = [sheet2];
const { rrweb, emit } = (window as unknown) as IWindow; const { rrweb, emit } = window as unknown as IWindow;
rrweb.record({ rrweb.record({
emit, emit,
}); });
@@ -602,7 +603,7 @@ describe('record', function (this: ISuite) {
sheet.replaceSync!('h1 {color: blue;}'); sheet.replaceSync!('h1 {color: blue;}');
shadowHost.shadowRoot!.adoptedStyleSheets = [sheet]; shadowHost.shadowRoot!.adoptedStyleSheets = [sheet];
const { rrweb, emit } = (window as unknown) as IWindow; const { rrweb, emit } = window as unknown as IWindow;
rrweb.record({ rrweb.record({
emit, emit,
}); });
@@ -639,11 +640,11 @@ describe('record', function (this: ISuite) {
}); });
await waitForRAF(ctx.page); await waitForRAF(ctx.page);
await ctx.page.evaluate(() => { await ctx.page.evaluate(() => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
inlineStylesheet: true, inlineStylesheet: true,
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
}); });
}); });
await waitForRAF(ctx.page); await waitForRAF(ctx.page);
@@ -683,11 +684,11 @@ describe('record', function (this: ISuite) {
it('captures stylesheets that are still loading', async () => { it('captures stylesheets that are still loading', async () => {
ctx.page.evaluate((serverURL) => { ctx.page.evaluate((serverURL) => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
inlineStylesheet: true, inlineStylesheet: true,
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
}); });
const link1 = document.createElement('link'); const link1 = document.createElement('link');
@@ -708,11 +709,11 @@ describe('record', function (this: ISuite) {
iframe.setAttribute('src', `/html/hello-world.html?2`); iframe.setAttribute('src', `/html/hello-world.html?2`);
document.body.appendChild(iframe); document.body.appendChild(iframe);
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
inlineStylesheet: true, inlineStylesheet: true,
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
}); });
}); });
@@ -743,11 +744,11 @@ describe('record', function (this: ISuite) {
// do not `await` the following function, otherwise `waitForResponse` _might_ not be called // do not `await` the following function, otherwise `waitForResponse` _might_ not be called
void ctx.page.evaluate((corsStylesheetURL) => { void ctx.page.evaluate((corsStylesheetURL) => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
inlineStylesheet: true, inlineStylesheet: true,
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
}); });
const link1 = document.createElement('link'); const link1 = document.createElement('link');
@@ -793,8 +794,9 @@ describe('record', function (this: ISuite) {
// Add stylesheet to an IFrame document. // Add stylesheet to an IFrame document.
const iframe = document.querySelector('iframe'); const iframe = document.querySelector('iframe');
const sheet3 = new (iframe!.contentWindow! as IWindow & const sheet3 = new (
typeof globalThis).CSSStyleSheet(); iframe!.contentWindow! as IWindow & typeof globalThis
).CSSStyleSheet();
sheet3.replaceSync!('h1 { color: blue; }'); sheet3.replaceSync!('h1 { color: blue; }');
iframe!.contentDocument!.adoptedStyleSheets = [sheet3]; iframe!.contentDocument!.adoptedStyleSheets = [sheet3];
@@ -803,8 +805,8 @@ describe('record', function (this: ISuite) {
ele.innerText = 'h1 in iframe'; ele.innerText = 'h1 in iframe';
iframe!.contentDocument!.body.appendChild(ele); iframe!.contentDocument!.body.appendChild(ele);
((window as unknown) as IWindow).rrweb.record({ (window as unknown as IWindow).rrweb.record({
emit: ((window.top as unknown) as IWindow).emit, emit: (window.top as unknown as IWindow).emit,
}); });
// Make incremental changes to shadow dom. // Make incremental changes to shadow dom.
@@ -819,8 +821,9 @@ describe('record', function (this: ISuite) {
document.adoptedStyleSheets = [sheet4, sheet, sheet2]; document.adoptedStyleSheets = [sheet4, sheet, sheet2];
const sheet5 = new (iframe!.contentWindow! as IWindow & const sheet5 = new (
typeof globalThis).CSSStyleSheet(); iframe!.contentWindow! as IWindow & typeof globalThis
).CSSStyleSheet();
sheet5.replaceSync!('h2 { color: purple; }'); sheet5.replaceSync!('h2 { color: purple; }');
iframe!.contentDocument!.adoptedStyleSheets = [sheet5, sheet3]; iframe!.contentDocument!.adoptedStyleSheets = [sheet5, sheet3];
}, 10); }, 10);
@@ -853,9 +856,9 @@ describe('record iframes', function (this: ISuite) {
it('captures iframe content in correct order', async () => { it('captures iframe content in correct order', async () => {
await ctx.page.evaluate(() => { await ctx.page.evaluate(() => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
}); });
}); });
await waitForRAF(ctx.page); await waitForRAF(ctx.page);
@@ -877,10 +880,10 @@ describe('record iframes', function (this: ISuite) {
it('captures stylesheet mutations in iframes', async () => { it('captures stylesheet mutations in iframes', async () => {
await ctx.page.evaluate(() => { await ctx.page.evaluate(() => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
// need to reference window.top for when we are in an iframe! // need to reference window.top for when we are in an iframe!
emit: ((window.top as unknown) as IWindow).emit, emit: (window.top as unknown as IWindow).emit,
}); });
const iframe = document.querySelector('iframe'); const iframe = document.querySelector('iframe');

View File

@@ -51,14 +51,14 @@ async function injectRecordScript(
}); });
options = options || {}; options = options || {};
await frame.evaluate((options) => { await frame.evaluate((options) => {
((window as unknown) as IWindow).snapshots = []; (window as unknown as IWindow).snapshots = [];
const { record, pack } = ((window as unknown) as IWindow).rrweb; const { record, pack } = (window as unknown as IWindow).rrweb;
const config: recordOptions<eventWithTime> = { const config: recordOptions<eventWithTime> = {
recordCrossOriginIframes: true, recordCrossOriginIframes: true,
recordCanvas: true, recordCanvas: true,
emit(event) { emit(event) {
((window as unknown) as IWindow).snapshots.push(event); (window as unknown as IWindow).snapshots.push(event);
((window as unknown) as IWindow).emit(event); (window as unknown as IWindow).emit(event);
}, },
}; };
if (options.usePackFn) { if (options.usePackFn) {
@@ -148,21 +148,21 @@ describe('cross origin iframes', function (this: ISuite) {
const frame = await el.contentFrame(); const frame = await el.contentFrame();
const events = await frame?.evaluate( const events = await frame?.evaluate(
() => ((window as unknown) as IWindow).snapshots, () => (window as unknown as IWindow).snapshots,
); );
expect(events).toMatchObject([]); expect(events).toMatchObject([]);
}); });
it('will emit events if it is in the top level iframe', async () => { it('will emit events if it is in the top level iframe', async () => {
const events = await ctx.page.evaluate( const events = await ctx.page.evaluate(
() => ((window as unknown) as IWindow).snapshots, () => (window as unknown as IWindow).snapshots,
); );
expect(events.length).not.toBe(0); expect(events.length).not.toBe(0);
}); });
it('should emit contents of iframe', async () => { it('should emit contents of iframe', async () => {
const events = await ctx.page.evaluate( const events = await ctx.page.evaluate(
() => ((window as unknown) as IWindow).snapshots, () => (window as unknown as IWindow).snapshots,
); );
await waitForRAF(ctx.page); await waitForRAF(ctx.page);
// two events (full snapshot + meta) from main frame, and one full snapshot from iframe // two events (full snapshot + meta) from main frame, and one full snapshot from iframe
@@ -171,7 +171,7 @@ describe('cross origin iframes', function (this: ISuite) {
it('should emit full snapshot event from iframe as mutation event', async () => { it('should emit full snapshot event from iframe as mutation event', async () => {
const events = await ctx.page.evaluate( const events = await ctx.page.evaluate(
() => ((window as unknown) as IWindow).snapshots, () => (window as unknown as IWindow).snapshots,
); );
await waitForRAF(ctx.page); await waitForRAF(ctx.page);
// two events from main frame, and two from iframe // two events from main frame, and two from iframe
@@ -193,7 +193,7 @@ describe('cross origin iframes', function (this: ISuite) {
it('should use unique id for child of iframes', async () => { it('should use unique id for child of iframes', async () => {
const events: eventWithTime[] = await ctx.page.evaluate( const events: eventWithTime[] = await ctx.page.evaluate(
() => ((window as unknown) as IWindow).snapshots, () => (window as unknown as IWindow).snapshots,
); );
await waitForRAF(ctx.page); await waitForRAF(ctx.page);
expect( expect(
@@ -211,7 +211,7 @@ describe('cross origin iframes', function (this: ISuite) {
await injectRecordScript(ctx.page.mainFrame().childFrames()[0]); // injects script into new iframe await injectRecordScript(ctx.page.mainFrame().childFrames()[0]); // injects script into new iframe
const events: eventWithTime[] = await ctx.page.evaluate( const events: eventWithTime[] = await ctx.page.evaluate(
() => ((window as unknown) as IWindow).snapshots, () => (window as unknown as IWindow).snapshots,
); );
expect( expect(
(events[events.length - 1].data as mutationData).removes, (events[events.length - 1].data as mutationData).removes,
@@ -343,7 +343,7 @@ describe('cross origin iframes', function (this: ISuite) {
it('should record custom events', async () => { it('should record custom events', async () => {
const frame = ctx.page.mainFrame().childFrames()[0]; const frame = ctx.page.mainFrame().childFrames()[0];
await frame.evaluate(() => { await frame.evaluate(() => {
((window as unknown) as IWindow).rrweb.addCustomEvent('test', { (window as unknown as IWindow).rrweb.addCustomEvent('test', {
id: 1, id: 1,
parentId: 1, parentId: 1,
nextId: 2, nextId: 2,
@@ -388,18 +388,17 @@ describe('cross origin iframes', function (this: ISuite) {
}); });
await waitForRAF(ctx.page); await waitForRAF(ctx.page);
await ctx.page.evaluate(() => { await ctx.page.evaluate(() => {
(document.adoptedStyleSheets![0] (
.cssRules[0] as CSSStyleRule).style.setProperty('color', 'green'); document.adoptedStyleSheets![0].cssRules[0] as CSSStyleRule
(document.adoptedStyleSheets![0] ).style.setProperty('color', 'green');
.cssRules[0] as CSSStyleRule).style.removeProperty('display'); (
document.adoptedStyleSheets![0].cssRules[0] as CSSStyleRule
).style.removeProperty('display');
}); });
await frame.evaluate(() => { await frame.evaluate(() => {
(document.adoptedStyleSheets![0] (
.cssRules[0] as CSSStyleRule).style.setProperty( document.adoptedStyleSheets![0].cssRules[0] as CSSStyleRule
'font-size', ).style.setProperty('font-size', 'medium', 'important');
'medium',
'important',
);
document.adoptedStyleSheets![0].insertRule('h2 { color: red; }'); document.adoptedStyleSheets![0].insertRule('h2 { color: red; }');
}); });
await waitForRAF(ctx.page); await waitForRAF(ctx.page);
@@ -445,8 +444,9 @@ describe('cross origin iframes', function (this: ISuite) {
'color', 'color',
'green', 'green',
); );
(document.styleSheets[0] (
.cssRules[0] as CSSStyleRule).style.removeProperty('display'); document.styleSheets[0].cssRules[0] as CSSStyleRule
).style.removeProperty('display');
}); });
await frame.evaluate(() => { await frame.evaluate(() => {
(document.styleSheets[0].cssRules[0] as CSSStyleRule).style.setProperty( (document.styleSheets[0].cssRules[0] as CSSStyleRule).style.setProperty(
@@ -596,7 +596,7 @@ describe('same origin iframes', function (this: ISuite) {
it('should emit contents of iframe once', async () => { it('should emit contents of iframe once', async () => {
const events = await ctx.page.evaluate( const events = await ctx.page.evaluate(
() => ((window as unknown) as IWindow).snapshots, () => (window as unknown as IWindow).snapshots,
); );
await waitForRAF(ctx.page); await waitForRAF(ctx.page);
// two events (full snapshot + meta) from main frame, // two events (full snapshot + meta) from main frame,

View File

@@ -64,13 +64,13 @@ const setup = function (
ctx.page.on('console', (msg) => console.log('PAGE LOG:', msg.text())); ctx.page.on('console', (msg) => console.log('PAGE LOG:', msg.text()));
await ctx.page.evaluate((canvasSample) => { await ctx.page.evaluate((canvasSample) => {
const { record } = ((window as unknown) as IWindow).rrweb; const { record } = (window as unknown as IWindow).rrweb;
record({ record({
recordCanvas: true, recordCanvas: true,
sampling: { sampling: {
canvas: canvasSample, canvas: canvasSample,
}, },
emit: ((window as unknown) as IWindow).emit, emit: (window as unknown as IWindow).emit,
}); });
}, canvasSample); }, canvasSample);
}); });

View File

@@ -22,9 +22,9 @@ describe('webglMutation', () => {
const createShaderMock = jest.fn().mockImplementation(() => { const createShaderMock = jest.fn().mockImplementation(() => {
return new WebGLShader(); return new WebGLShader();
}); });
const context = ({ const context = {
createShader: createShaderMock, createShader: createShaderMock,
} as unknown) as WebGLRenderingContext; } as unknown as WebGLRenderingContext;
jest.spyOn(canvas, 'getContext').mockImplementation(() => { jest.spyOn(canvas, 'getContext').mockImplementation(() => {
return context; return context;
}); });

View File

@@ -597,7 +597,9 @@ describe('replayer', function () {
expect( expect(
await iframeTwoDocument!.evaluate( await iframeTwoDocument!.evaluate(
(iframe) => (iframe as HTMLIFrameElement)!.contentDocument!.doctype, (iframe) => (iframe as HTMLIFrameElement)!.contentDocument!.doctype,
(await iframeTwoDocument!.$$('iframe'))[1], (
await iframeTwoDocument!.$$('iframe')
)[1],
), ),
).not.toBeNull(); ).not.toBeNull();
}); });

View File

@@ -17,7 +17,7 @@ import * as url from 'url';
import * as fs from 'fs'; import * as fs from 'fs';
export async function launchPuppeteer( export async function launchPuppeteer(
options?: Parameters<typeof puppeteer['launch']>[0], options?: Parameters<(typeof puppeteer)['launch']>[0],
) { ) {
return await puppeteer.launch({ return await puppeteer.launch({
headless: process.env.PUPPETEER_HEADLESS ? true : false, headless: process.env.PUPPETEER_HEADLESS ? true : false,
@@ -119,7 +119,8 @@ function stringifySnapshots(snapshots: eventWithTime[]): string {
s.data.href = 'about:blank'; s.data.href = 'about:blank';
} }
// FIXME: travis coordinates seems different with my laptop // FIXME: travis coordinates seems different with my laptop
const coordinatesReg = /(bottom|top|left|right|width|height): \d+(\.\d+)?px/g; const coordinatesReg =
/(bottom|top|left|right|width|height): \d+(\.\d+)?px/g;
if ( if (
s.type === EventType.IncrementalSnapshot && s.type === EventType.IncrementalSnapshot &&
s.data.source === IncrementalSource.MouseInteraction s.data.source === IncrementalSource.MouseInteraction
@@ -178,10 +179,8 @@ function stringifySnapshots(snapshots: eventWithTime[]): string {
add.node.attributes.rr_dataURL && add.node.attributes.rr_dataURL &&
typeof add.node.attributes.rr_dataURL === 'string' typeof add.node.attributes.rr_dataURL === 'string'
) { ) {
add.node.attributes.rr_dataURL = add.node.attributes.rr_dataURL.replace( add.node.attributes.rr_dataURL =
/,.+$/, add.node.attributes.rr_dataURL.replace(/,.+$/, ',...');
',...',
);
} }
} }
}); });
@@ -284,7 +283,7 @@ export function stripBase64(events: eventWithTime[]) {
const base64Strings: string[] = []; const base64Strings: string[] = [];
function walk<T>(obj: T): T { function walk<T>(obj: T): T {
if (!obj || typeof obj !== 'object') return obj; if (!obj || typeof obj !== 'object') return obj;
if (Array.isArray(obj)) return (obj.map((e) => walk(e)) as unknown) as T; if (Array.isArray(obj)) return obj.map((e) => walk(e)) as unknown as T;
const newObj: Partial<T> = {}; const newObj: Partial<T> = {};
for (const prop in obj) { for (const prop in obj) {
const value = obj[prop]; const value = obj[prop];

934
yarn.lock

File diff suppressed because it is too large Load Diff