Support top-layer <dialog> recording & replay (#1503)

* chore: its important to run `yarn build:all` before running `yarn dev`

* feat: trigger showModal from rrdom and rrweb

* feat: Add support for replaying modal and non modal dialog elements

* chore: Update dev script to remove CLEAR_DIST_DIR flag

* Get modal recording and replay working

* DRY up dialog test and dedupe snapshot images

* feat: Refactor dialog test to use updated attribute name

* feat: Update dialog test to include rr_open attribute

* chore: Add npm dependency happy-dom@14.12.0

* Add more test cases for dialog

* Clean up naming

* Refactor dialog open code

* Revert changed code that doesn't do anything

* Add documentation for unimplemented type

* chore: Remove unnecessary comments in dialog.test.ts

* rename rr_open to rr_openMode

* Replace todo with a skipped test

* Add better logging for CI

* Rename rr_openMode to rr_open_mode

rrdom downcases all attribute names which made `rr_openMode` tricky to deal with

* Remove unused images

* Move after iframe append based on @YunFeng0817's comment
https://github.com/rrweb-io/rrweb/pull/1503#discussion_r1666363931

* Remove redundant dialog handling from rrdom.

rrdom already handles dialog element creation it's self

* Rename variables for dialog handling in rrweb replay module

* Update packages/rrdom/src/document.ts

---------

Co-authored-by: Eoghan Murray <eoghan@getthere.ie>
This commit is contained in:
Justin Halsall
2026-04-01 12:00:00 +08:00
committed by GitHub
parent c110e1c21d
commit 5217a09c60
38 changed files with 1902 additions and 75 deletions

View File

@@ -287,6 +287,11 @@ function buildNode(
(node as HTMLMediaElement).loop = value;
} else if (name === 'rr_mediaVolume' && typeof value === 'number') {
(node as HTMLMediaElement).volume = value;
} else if (name === 'rr_open_mode') {
(node as HTMLDialogElement).setAttribute(
'rr_open_mode',
value as string,
); // keep this attribute for rrweb to trigger showModal
}
}

View File

@@ -6,6 +6,7 @@ import {
type MaskInputOptions,
type SlimDOMOptions,
type DataURLOptions,
type DialogAttributes,
type MaskTextFn,
type MaskInputFn,
type KeepIframeSrcFn,
@@ -652,6 +653,16 @@ function serializeElementNode(
delete attributes.selected;
}
}
if (tagName === 'dialog' && (n as HTMLDialogElement).open) {
// register what type of dialog is this
// `modal` or `non-modal`
// this is used to trigger `showModal()` or `show()` on replay (outside of rrweb-snapshot, in rrweb)
(attributes as DialogAttributes).rr_open_mode = n.matches('dialog:modal')
? 'modal'
: 'non-modal';
}
// canvas image data
if (tagName === 'canvas' && recordCanvas) {
if ((n as ICanvas).__context === '2d') {

View File

@@ -103,6 +103,23 @@ export type mediaAttributes = {
rr_mediaVolume?: number;
};
export type DialogAttributes = {
open: string;
/**
* Represents the dialog's open mode.
* `modal` means the dialog is opened with `showModal()`.
* `non-modal` means the dialog is opened with `show()` or
* by adding an `open` attribute.
*/
rr_open_mode: 'modal' | 'non-modal';
/**
* Currently unimplemented, but in future can be used to:
* Represents the order of which of the dialog was opened.
* This is useful for replaying the dialog `.showModal()` in the correct order.
*/
// rr_open_mode_index?: number;
};
// @deprecated
export interface INode extends Node {
__sn: serializedNodeWithId;