Commit Graph

67 Commits

Author SHA1 Message Date
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
Yanzhen Yu
f3e118ef39 add an experiment config to set max speed in fast forward 2021-03-08 14:11:56 +08:00
Yanzhen Yu
34651c40fe fix lint errors 2021-02-27 18:21:54 +08:00
Yanzhen Yu
860ff38e90 close #501 do not count attach iframe event in checkout 2021-02-27 13:32:21 +08:00
Province Innovation
75e4a0c1ff Added mousemoveCallback threshold option to sampling config. (#492)
* Added mousemoveCallback threshold option to sampling config.

* Added mousemoveCallback to definitions file.
2021-02-19 11:56:12 +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
Lucky Feng
4e7146e72b feat: enable rrweb to record and replay log messages in console (#424)
* wip: working on rrweb logger

* wip: can record and replay some simple log

* wip: can record and replay log's stack

* wip: try to serialize object

* wip: record and replay console logger

hijack all of the console functions.
add listener to thrown errors

* wip: record and replay console logger
add limit to the max number of log records

* feat: enable rrweb to record and replay log messages in console

this is the implementation of new feature request(issue #234)

here are a few points of description.
1. users need to set recordLog option in rrweb.record's parameter to record log messages.  The log recorder is off by default.
2. support recording and replaying all kinds of console functions. But the reliability of them should be tested more
3. the stringify function in  stringify.ts needs improvement. e.g. robustness, handler for cyclical structures and better support for more kinds of object
4. we can replay the log messages in a simulated html console like LogRocket by implementing the interface "ReplayLogger" in the future

* improve: the stringify function

1. handle cyclical structures
2. add stringify option to limit the length of result
3. handle function type

* refactor: simplify the type definition of ReplayLogger
2020-11-29 18:12:03 +08:00
Yanzhen Yu
23a1883dfc pick #286 allow short cut for slim DOM options 2020-11-29 14:54:05 +08:00
Yanzhen Yu
3d5f2e2719 pick #286, export slim DOM options 2020-11-29 14:19:25 +08:00
Yanzhen Yu
a42b6419c3 expose blockSelector as a public option 2020-11-29 13:59:25 +08:00
Lucky Feng
96e4bfdddd 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
2020-11-27 17:46:52 +08:00
Lucky Feng
658999c6e0 feat: add an option to determine whether to pause CSS animation when playback is paused (#428)
set pauseAnimation to true by default
2020-11-27 16:16:18 +08:00
Yaozu Lv
a2cd3e2da0 Add record option maskInputFn for custom mask input function (#409) 2020-11-15 16:39:17 +08:00
Yanzhen Yu
2440701926 impl #309 observe font face set changes 2020-09-17 02:11:34 +08:00
Yanzhen Yu
0688bb6353 close #51 add mouse tail feature 2020-09-07 14:52:57 +08:00
Yanzhen Yu
cdebe18803 close #320 use emitter handler to catch before load state 2020-09-06 18:14:11 +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
a90999d96e close #274 implement the new state management proposal 2020-08-08 17:07:37 +08:00
yz-yu
7de7eb5e54 mask input options and sampling options (#252)
* part of #80, support mask input options

* close #188 enhance sampling options
Use a more general sampling strategy interface to describe the
configuration of sampling events collection.

Implemented mousmove, mouse interaction, scroll and input sampling
strategy.
2020-07-18 15:05:19 +08:00
yz-yu
e2cc42e393 fix the skip event calculation (#242) 2020-07-11 17:06:56 +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
Eoghan Murray
8766335c82 Move mutation processing into it's own class (#223)
* Move mutation processing into it's own object.

This should stand on it's own as a refactor, but is intended as a basis
for exposing the new MutationBuffer object to further outside control e.g.
to 'mute' or batch up mutation emission when the page becomes inactive
from a https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
point of view

* The `processMutations` function needed to be bound to the `mutationBuffer` object, as otherwise `this` referred to the `MutationObserver` object itself

* Neglected to add this output of `npm run typings`

* Get around the binding problem by using Arrow function expressions

* Prettier formatting
2020-06-06 18:33:58 +08:00
Rifaudeen
45a7f89f2b added custom-event emitter to replayer (#219) 2020-05-23 15:20:41 +08:00
yz-yu
7a666293b6 mutation observer v2 (#206)
There are some long-term issues in rrweb's mutation observer.

A scenario cause problem:
A list of DOM node: n1, n2, n3, n4, n5
Steps of modifying the nodes:
  1. remove n1, n2, n3, n4 sequentially
  2. append n4, n3, n2, n1 after n5 sequentially
Then we got the added node data like this:
  (id: n4, prev: null, next: n3  )
  (id: n3, prev: n4,   next: n2  )
  (id: n2, prev: n3,   next: n1  )
  (id: n1, prev: n2,   next: null)
The problem comes when we try to replay the first add node datum.
Since its prev node is null, we rely on its next sibling n3. But
n3 was not present at this moment, and in previous code, we fallback
to append n4 to the last of its parent node.

The solution is to defer the append of elements that missing
siblings. But it is also hard to tell which node is the first one
that needs to be appended.

Take a step back and rethink the design of the mutation observer,
we've found there are two implementations make things complicated.
1. We set the id to -1 when we seeing some nodes are not serialized yet.
2. We record both previous sibling and next sibling to determine the
position of the node.
But we can do better!
First, we can put nodes with un-serialized siblings
to a queue, and try to add it again later. Then we can just record the next
sibling as 'the single truth' so we can be sure which node is the last
one of its parent.

This patch has implemented the new observer strategy. Data recorded with
the new observer should no longer have any node with id -1. But for
compatibility consideration, we still keep some replayer code that helps
solve legacy data.
2020-05-02 14:08:10 +08:00
yz-yu
4f36d0e57d Packer (#172)
* introduce pako and add general packer interface

* add tests for packer

* use function API instead of class API for better tree shaking support

* refcatoring the rollup bundle config
2020-04-07 18:03:47 +08:00
Yanzhen Yu
29296b6877 add trigger focus option to replayer, which may helps integration into other apps 2020-02-28 19:48:36 +08:00
David Cramer
046936b3e8 Add observers for stylesheet mutations (#177)
* hack together stylesheet observer

* Add test coverage for insertRule/deleteRule on stylesheets

* Add new observers

* update patch based on changes to master

* Functioning event recording

* Remove print statements

* Fix ID usage and mark add vs remove

* Correct type

Co-authored-by: Jon Perl <perl.jonathan@gmail.com>
2020-02-22 12:59:55 +08:00
Yanzhen Yu
abfb90a778 impl media interactions recording
close #159
close #72
listen to HTMLMediaElement's play/pause events, and replay them
by programmatically play and pause the target element.
2020-01-12 21:37:01 +08:00
Yanzhen Yu
2d07b37701 close #153 emit event when it being casted 2019-12-08 16:45:21 +08:00
mpstv
6a5d0610b7 Try add configurable threshold for events throttling (#147) 2019-11-16 21:25:34 +08:00
yz-yu
b64e1492ab add hooks API (#132) 2019-09-17 23:33:38 +08:00
Yanzhen Yu
56c025fde3 close #84 set mousemoveData's source by event source 2019-08-04 15:06:06 +08:00
Yanzhen Yu
f78070a824 impl #81 custom event
This is the record side impl of custom event, according to the
issue, we may also add first-class support for the custom event
tag like display color labels in the replayer-ui.
2019-07-24 22:32:11 +08:00
肉肉肉肉
b569b84794 new feature: add custom style in replayer (#87)
* new feature: add custom style in replayer

* concat style rules for loop
2019-07-10 12:33:54 +08:00
Yanzhen Yu
d43aa974f5 fix#71 fix touch event listener and throttle touch move callback 2019-06-17 18:07:30 +08:00
Sebastian Jakob
189df87b9d Option to mask inputs (#80)
* Option to mask inputs

Added option 'maskAllInputs' to replace all user inputs with an Asterisk.

* Update types.d.ts
2019-06-15 12:52:08 +08:00
Yanzhen Yu
d32b31f3e3 remove mitt typings namesapce 2019-06-05 17:33:20 +08:00
yz-yu
2398f5c0b1 start to support live mode (#73)
1. add a liveMode flag to config, when liveMode is set, the timer
will keep running even though all the actions casted
2. add a public method addEvent, which will cast newly added event
in sync
3. move mouse in sync mode with the latest position info
2019-05-26 16:02:52 +08:00
Yanzhen Yu
107296eee3 add the inline stylesheet option when recording 2019-05-12 21:10:34 +08:00
Yanzhen Yu
2d8d4b0c19 fix #62 accept RegExp type block class config 2019-04-14 16:11:54 +08:00
Yanzhen Yu
059cbe4fd8 move browser related APIs into runtime 2019-04-02 21:29:14 +08:00
Yanzhen Yu
c04e4bf0a5 impl #23 add custom privacy selectors 2019-04-02 00:25:08 +08:00
Yanzhen Yu
ebd1457ce2 turn some warning message into debug message 2019-01-30 00:47:41 +08:00
Yanzhen Yu
6abf4fd4a0 move all events to an enum and update guide 2019-01-25 17:18:51 +08:00
yz-yu
3daedfa284 fix remove node observer and check on the result of getNode (#43)
* check removed node and its parent before collect

* add more more checks on the result of getNode
2019-01-21 19:18:51 +08:00
yz-yu
cedc87c69e add checkout config to recorder (#36)
* add checkout config to recorder

* add test cases for checkout feature and extract assertSnapshot method
2019-01-11 10:52:04 +08:00
Yanzhen Yu
6973ce2c8d resolve #13 add warning messages when target is not found 2019-01-05 14:18:07 +08:00
Yanzhen Yu
aaa8bb9e94 add skipInactive option
Skip inactive time is an important and useful feature. We consider
user interaction events as active, and check next user interaction
event after apply incremental snapshot.
If next user interaction event has a time gap larger than the
threshold, we will set a dynamic speed value which will skip the
inactive time interval in about 5 seconds.
2018-12-26 18:05:55 +08:00
Yanzhen Yu
2c0a0edf36 basic impl of wait for stylesheet loaded 2018-11-26 18:19:07 +08:00
edwardwu
6382315d43 resolve #4 Improve timer's performance by storing all callbacks in an array (#5) 2018-11-16 21:53:59 +08:00