Commit Graph

38 Commits

Author SHA1 Message Date
Yanzhen Yu
df7537b01d impl shadow DOM manager
part of #38
1. observe DOM mutations in shadow DOM
2. rebuild DOM mutations in shadow DOM
2021-03-28 18:16:54 +08:00
Lucky Feng
e3f9a4d205 fix: inaccurate mouse position (#522)
1. Position of mouse was inaccurate when replaying and this PR will fix it.
2. Fix the bug that if one nested iframe has a scale transform and the position of mouse was inaccurate as well.
2021-03-25 10:29:49 +08:00
yz-yu
f3d7fa3451 Impl record iframe (#481)
* Impl record iframe

* iframe observe

* temp: add bundle file to git

* update bundle

* update with pick

* update bundle

* fix fragment map remove

* feat: add an option to determine whether to pause CSS animation when playback is paused (#428)

set pauseAnimation to true by default

* fix: elements would lose some states like scroll position because of "virtual parent" optimization (#427)

* fix: elements would lose some state like scroll position because of "virtual parent" optimization

* refactor: the bugfix code

bug: elements would lose some state like scroll position because of "virtual parent" optimization

* fix: an error occured at applyMutation(remove nodes part)

error message:
Uncaught (in promise) DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node

* pick fixes

* revert ignore file

* re-impl iframe record

* re-impl iframe replay

* code housekeeping

* move multi layer dimension calculation to replay side

* update test cases

* teardown test server

* upgrade rrweb-snapshot with iframe load timeout

Co-authored-by: Lucky Feng <yun.feng@smartx.com>
2021-02-10 21:44:25 +08:00
Yanzhen Yu
3d5f2e2719 pick #286, export slim DOM options 2020-11-29 14:19:25 +08:00
Yanzhen Yu
6cef61882e optimize the append queue algorithm
Loop the append queue has been proved to be very inefficient, and
some times lead to N^2 time complexity.

Especially when some abnormal data could not be appended into the
real DOM, will make a dead loop.

Previously we use a 5000ms time out to handle this, which is not
user-friendly and not explicitly.

In this patch, we transform the queue into a tree data structure,
which reflects the layout of real DOM. With the tree data structure,
we can find whether there are dangling nodes that need to be dropped.
Also, the iteration will be much more efficient.

There is still a 500ms time out to avoid a dead loop, but should not
be called in expected scenarios.
2020-10-24 15:35:02 +08:00
Yanzhen Yu
8065415de6 Release 0.9.6 2020-09-21 14:01:56 +08:00
jackycoder
f8e88ced7b compatibility fixes (#358)
* fix polyfill NodeList forEach

* contentDocument.contains for IE

* polyfill DOMTokenList forEach
2020-09-20 18:55:29 +08:00
jackycoder
ef84f844ae fix polyfill NodeList forEach (#357) 2020-09-20 15:25:50 +08:00
Justin Halsall
65d0d4e54a child nodes without __sn now remove without error (#307) 2020-09-20 12:58:23 +08:00
yz-yu
772c0e021a record canvas mutations (#296)
* record canvas mutations

close #60, #261

This patch implements the canvas mutation observer.
It consists of both the record and the replay side changes.

In the record side, we add a `recordCanvas` flag to indicate
whether to record canvas elements and the flag defaults to false.
Different from our other observers, the canvas observer was
disabled by default. Because some applications with heavy canvas
usage may emit a lot of data as canvas changed, especially the
scenarios that use a lot of `drawImage` API.
So the behavior should be audited by users and only record canvas
when the flag was set to true.

In the replay side, we add a `UNSAFE_replayCanvas` flag to indicate
whether to replay canvas mutations.
Similar to the `recordCanvas` flag, `UNSAFE_replayCanvas` defaults
to false. But unlike the record canvas implementation is stable and
safe, the replay canvas implementation is UNSAFE.
It's unsafe because we need to add `allow-scripts` to the replay
sandbox, which may cause some unexpected script execution. Currently,
users should be aware of this implementation detail and enable this
feature carefully.

* update canvas integration test
2020-08-22 16:44:02 +08:00
Yanzhen Yu
ad32b8be8d close #240 fix block class to handle text node changes 2020-07-18 17:36:33 +08:00
Yanzhen Yu
6f08ec3ca7 add the patch function to utils 2020-07-18 16:56:22 +08:00
Yanzhen Yu
4bf533a675 fast-forward implementation v1
related to #6

Since the currently 'play at any time offset' implementation is pretty simple,
there are many things we can do to optimize its performance.

In this patch, we do the following optimizations:
1. Ignore some of the events during fast forward.
   For example, when we are going to fast forward to 10 minutes later,
   we do not need to perform mouse movement events during this period.
2. Use a fragment element as the 'virtual parent node'.
   So newly added DOM nodes will be appended to this fragment node,
   and finally being appended into the document as a batch operation.
These changes reduce a lot of time which was spent on reflow/repaint previously.
I've seen a 10 times performance improvement within these approaches.

And there are still some things we can do better but not in this patch.
1. We can build a virtual DOM tree to store the mutations of DOM.
   This will minimize the number of DOM operations.
2. Another thing that may help UX is to make the fast forward process async and cancellable.
   This may make the drag and drop interactions in the player's UI looks smooth.
2020-07-11 11:03:40 +08:00
Yanzhen Yu
4cf196718c export utils as public API 2020-06-15 17:10:18 +08:00
Yanzhen Yu
a95759fc9c hotfix throttle function args 2019-08-11 14:41:06 +08:00
Yanzhen Yu
3269089e1f fix#110 add NodeList forEach polyfill 2019-08-07 23:51:40 +08:00
Yanzhen Yu
56c025fde3 close #84 set mousemoveData's source by event source 2019-08-04 15:06:06 +08:00
shenchenxh
61a3c9f8f6 fix 100 (#102) 2019-07-26 16:21:02 +08:00
Yanzhen Yu
d43aa974f5 fix#71 fix touch event listener and throttle touch move callback 2019-06-17 18:07:30 +08:00
Yanzhen Yu
2d8d4b0c19 fix #62 accept RegExp type block class config 2019-04-14 16:11:54 +08:00
Yanzhen Yu
c04e4bf0a5 impl #23 add custom privacy selectors 2019-04-02 00:25:08 +08:00
Yanzhen Yu
a69bf87f7f check whether the removed node's ancestors has been removed 2019-02-01 23:13:00 +08:00
Yanzhen Yu
8f24cb78b3 fix block strategy
If an element was blocked, its child nodes should also be blocked.
The interactions and mutations on the element and its child nodes
also need to be blocked.
2018-12-30 21:46:23 +08:00
Yanzhen Yu
78967192fc return stopper function as the result of record 2018-12-02 22:37:28 +08:00
Yanzhen Yu
0fb8fc4e0b Fix add node logic with missingNextNodeMap
This patch include a breaking change to the recorder's event data.

We used to consider mirror.getId will always return the id of the
target node because we keep serialize every node. But if we call
mirror.getId before serialization then bug happened. This could
happen when we get nextId of newly added nodes if its next sibling
was also newly added.
So we have to return -1 as the id of node which was not serialized
and when we building added nodes in the replayer we should handle
this.

For example, nodes el1, el2 were added together and el1's nextId
will be -1 since el2 was not serialized at that moment. Now we
call el1 as a 'missing next node' and not append it into the DOM
tree after building, instead we store it in a missingNextNodeMap.
After a added node in the same mutation was successfully appened
we will check whether it has a previous id and the id was pointed
to some nodes in the map, if so, we will insert that node before
it and delete the node from map.
2018-11-02 19:23:03 +08:00
Yanzhen Yu
8acf670a99 add a has method to mirror for checking whether an id is in the map 2018-10-31 12:06:32 +08:00
Yanzhen Yu
d588f738b8 rewrite mutation observer handler with lazy child list calculation 2018-10-22 23:08:05 +08:00
Yanzhen Yu
a88a79d821 add meta event and fix childList observer, also update related replayer 2018-10-22 10:48:56 +08:00
Yanzhen Yu
6c8cf5c379 implemented the play any offset feature 2018-10-18 16:24:01 +08:00
Yanzhen Yu
49cd7b4db3 align id map by skip extra added nodes 2018-10-16 15:29:52 +08:00
Yanzhen Yu
2816726e23 impl replay the mutations and mouse interactions 2018-10-15 12:37:47 +08:00
Yanzhen Yu
85a56d2047 fix scroll value and record viewport when loaded 2018-10-12 13:08:03 +08:00
Yanzhen Yu
215b2b319b update bundle configs 2018-10-11 16:46:34 +08:00
Yanzhen Yu
40f29e5353 add input event observer and hook the value setter 2018-10-11 16:12:32 +08:00
Yanzhen Yu
46ab1d6e80 serialize newly added nodes and update id node map when childList changed 2018-10-09 10:52:20 +08:00
Yanzhen Yu
1f10b70d30 add scroll and viewport resize observers 2018-10-09 10:33:24 +08:00
Yanzhen Yu
a33b24a676 add mouse movement observer 2018-10-08 17:46:15 +08:00
Yanzhen Yu
427acff3d6 change observed mutations into serializable records 2018-10-08 15:47:21 +08:00