Skip to content
Closed
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
24 changes: 22 additions & 2 deletions packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
mousemoveCallBack,
mousePosition,
mouseInteractionCallBack,
mouseInteractionParam,
clickParam,
MouseInteractions,
listenerHandler,
scrollCallback,
Expand Down Expand Up @@ -286,12 +288,30 @@ function initMouseInteractionObserver(
}
const id = mirror.getId(target as INode);
const { clientX, clientY } = e;
cb({
let emissionEvent: mouseInteractionParam | clickParam = {
type: MouseInteractions[eventKey],
id,
x: clientX,
y: clientY,
});
}
const htarget = (target as Element);
if (MouseInteractions[eventKey] === MouseInteractions.Click) {
let href: string | null = null;
if (htarget.tagName.toLowerCase() === 'a' &&
(htarget as HTMLAnchorElement).href) {
href = (htarget as HTMLAnchorElement).href;
} else if (htarget.tagName.toLowerCase() === 'area' &&
(htarget as HTMLAreaElement).href) {
href = (htarget as HTMLAreaElement).href;
}
if (href !== null) {
emissionEvent = {
...emissionEvent,
href: href,
};
}
}
cb(emissionEvent);
};
};
Object.keys(MouseInteractions)
Expand Down
8 changes: 6 additions & 2 deletions packages/rrweb/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,18 @@ export enum MouseInteractions {
TouchEnd,
}

type mouseInteractionParam = {
export type mouseInteractionParam = {
type: MouseInteractions;
id: number;
x: number;
y: number;
};

export type mouseInteractionCallBack = (d: mouseInteractionParam) => void;
export type clickParam = mouseInteractionParam & {
href?: string;
};

export type mouseInteractionCallBack = (d: mouseInteractionParam | clickParam) => void;

export type scrollPosition = {
id: number;
Expand Down
261 changes: 261 additions & 0 deletions packages/rrweb/test/__snapshots__/integration.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2737,6 +2737,267 @@ exports[`ignore 1`] = `
]"
`;

exports[`link 1`] = `
"[
{
\\"type\\": 0,
\\"data\\": {}
},
{
\\"type\\": 1,
\\"data\\": {}
},
{
\\"type\\": 4,
\\"data\\": {
\\"href\\": \\"about:blank\\",
\\"width\\": 1920,
\\"height\\": 1080
}
},
{
\\"type\\": 2,
\\"data\\": {
\\"node\\": {
\\"type\\": 0,
\\"childNodes\\": [
{
\\"type\\": 1,
\\"name\\": \\"html\\",
\\"publicId\\": \\"\\",
\\"systemId\\": \\"\\",
\\"id\\": 2
},
{
\\"type\\": 2,
\\"tagName\\": \\"html\\",
\\"attributes\\": {
\\"lang\\": \\"en\\"
},
\\"childNodes\\": [
{
\\"type\\": 2,
\\"tagName\\": \\"head\\",
\\"attributes\\": {},
\\"childNodes\\": [
{
\\"type\\": 3,
\\"textContent\\": \\"\\\\n \\",
\\"id\\": 5
},
{
\\"type\\": 2,
\\"tagName\\": \\"meta\\",
\\"attributes\\": {
\\"charset\\": \\"UTF-8\\"
},
\\"childNodes\\": [],
\\"id\\": 6
},
{
\\"type\\": 3,
\\"textContent\\": \\"\\\\n \\",
\\"id\\": 7
},
{
\\"type\\": 2,
\\"tagName\\": \\"meta\\",
\\"attributes\\": {
\\"name\\": \\"viewport\\",
\\"content\\": \\"width=device-width, initial-scale=1.0\\"
},
\\"childNodes\\": [],
\\"id\\": 8
},
{
\\"type\\": 3,
\\"textContent\\": \\"\\\\n \\",
\\"id\\": 9
},
{
\\"type\\": 2,
\\"tagName\\": \\"meta\\",
\\"attributes\\": {
\\"http-equiv\\": \\"X-UA-Compatible\\",
\\"content\\": \\"ie=edge\\"
},
\\"childNodes\\": [],
\\"id\\": 10
},
{
\\"type\\": 3,
\\"textContent\\": \\"\\\\n\\\\t\\",
\\"id\\": 11
},
{
\\"type\\": 2,
\\"tagName\\": \\"title\\",
\\"attributes\\": {},
\\"childNodes\\": [
{
\\"type\\": 3,
\\"textContent\\": \\"Link click\\",
\\"id\\": 13
}
],
\\"id\\": 12
},
{
\\"type\\": 3,
\\"textContent\\": \\"\\\\n \\",
\\"id\\": 14
}
],
\\"id\\": 4
},
{
\\"type\\": 3,
\\"textContent\\": \\"\\\\n \\",
\\"id\\": 15
},
{
\\"type\\": 2,
\\"tagName\\": \\"body\\",
\\"attributes\\": {},
\\"childNodes\\": [
{
\\"type\\": 3,
\\"textContent\\": \\"\\\\n\\\\t \\",
\\"id\\": 17
},
{
\\"type\\": 2,
\\"tagName\\": \\"span\\",
\\"attributes\\": {
\\"id\\": \\"not-a-link\\"
},
\\"childNodes\\": [
{
\\"type\\": 3,
\\"textContent\\": \\"not link\\",
\\"id\\": 19
}
],
\\"id\\": 18
},
{
\\"type\\": 3,
\\"textContent\\": \\"\\\\n\\\\t \\",
\\"id\\": 20
},
{
\\"type\\": 2,
\\"tagName\\": \\"a\\",
\\"attributes\\": {
\\"href\\": \\"about:blank#clicked\\"
},
\\"childNodes\\": [
{
\\"type\\": 3,
\\"textContent\\": \\"link\\",
\\"id\\": 22
}
],
\\"id\\": 21
},
{
\\"type\\": 3,
\\"textContent\\": \\"\\\\n \\\\n \\",
\\"id\\": 23
},
{
\\"type\\": 2,
\\"tagName\\": \\"script\\",
\\"attributes\\": {},
\\"childNodes\\": [
{
\\"type\\": 3,
\\"textContent\\": \\"SCRIPT_PLACEHOLDER\\",
\\"id\\": 25
}
],
\\"id\\": 24
},
{
\\"type\\": 3,
\\"textContent\\": \\"\\\\n \\\\n \\\\n\\\\n\\",
\\"id\\": 26
}
],
\\"id\\": 16
}
],
\\"id\\": 3
}
],
\\"id\\": 1
},
\\"initialOffset\\": {
\\"left\\": 0,
\\"top\\": 0
}
}
},
{
\\"type\\": 3,
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 18
}
},
{
\\"type\\": 3,
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 18
}
},
{
\\"type\\": 3,
\\"data\\": {
\\"source\\": 2,
\\"type\\": 2,
\\"id\\": 18
}
},
{
\\"type\\": 3,
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 21
}
},
{
\\"type\\": 3,
\\"data\\": {
\\"source\\": 2,
\\"type\\": 5,
\\"id\\": 21
}
},
{
\\"type\\": 3,
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 21
}
},
{
\\"type\\": 3,
\\"data\\": {
\\"source\\": 2,
\\"type\\": 2,
\\"id\\": 21,
\\"href\\": \\"about:blank#clicked\\"
}
}
]"
`;

exports[`log 1`] = `
"[
{
Expand Down
13 changes: 13 additions & 0 deletions packages/rrweb/test/html/link.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Link click</title>
</head>
<body>
<span id="not-a-link">not link</span>
<a href="#clicked">link</a>
</body>
</html>
11 changes: 11 additions & 0 deletions packages/rrweb/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ describe('record integration tests', function (this: ISuite) {
this.server.close();
});

it('can record clicks', async () => {
const page: puppeteer.Page = await this.browser.newPage();
await page.goto('about:blank');
await page.setContent(getHtml.call(this, 'link.html'));
await page.click('span');
await page.click('a');

const snapshots = await page.evaluate('window.snapshots');
assertSnapshot(snapshots, __filename, 'link');
});

it('can record form interactions', async () => {
const page: puppeteer.Page = await this.browser.newPage();
await page.goto('about:blank');
Expand Down