@betterbugs/utils 2.0.0-alpha.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Readme.md +178 -0
- package/dist/index.d.cts +61 -0
- package/dist/index.d.ts +61 -0
- package/dist/utils.cjs +190 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.js +190 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.umd.cjs +220 -0
- package/dist/utils.umd.cjs.map +7 -0
- package/dist/utils.umd.min.cjs +32 -0
- package/dist/utils.umd.min.cjs.map +7 -0
- package/package.json +54 -0
package/Readme.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# @rrweb/utils
|
|
2
|
+
|
|
3
|
+
This package contains the shared utility functions used across rrweb packages.
|
|
4
|
+
See the [guide](../../guide.md) for more info on rrweb.
|
|
5
|
+
|
|
6
|
+
## Sponsors
|
|
7
|
+
|
|
8
|
+
[Become a sponsor](https://opencollective.com/rrweb#sponsor) and get your logo on our README on Github with a link to your site.
|
|
9
|
+
|
|
10
|
+
### Gold Sponsors 🥇
|
|
11
|
+
|
|
12
|
+
<div dir="auto">
|
|
13
|
+
|
|
14
|
+
<a href="https://opencollective.com/rrweb/tiers/gold-sponsor/0/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/gold-sponsor/0/avatar.svg?requireActive=false&avatarHeight=225" alt="sponsor"></a>
|
|
15
|
+
<a href="https://opencollective.com/rrweb/tiers/gold-sponsor/1/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/gold-sponsor/1/avatar.svg?requireActive=false&avatarHeight=225" alt="sponsor"></a>
|
|
16
|
+
<a href="https://opencollective.com/rrweb/tiers/gold-sponsor/2/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/gold-sponsor/2/avatar.svg?requireActive=false&avatarHeight=225" alt="sponsor"></a>
|
|
17
|
+
<a href="https://opencollective.com/rrweb/tiers/gold-sponsor/3/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/gold-sponsor/3/avatar.svg?requireActive=false&avatarHeight=225" alt="sponsor"></a>
|
|
18
|
+
<a href="https://opencollective.com/rrweb/tiers/gold-sponsor/4/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/gold-sponsor/4/avatar.svg?requireActive=false&avatarHeight=225" alt="sponsor"></a>
|
|
19
|
+
<a href="https://opencollective.com/rrweb/tiers/gold-sponsor/5/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/gold-sponsor/5/avatar.svg?requireActive=false&avatarHeight=225" alt="sponsor"></a>
|
|
20
|
+
<a href="https://opencollective.com/rrweb/tiers/gold-sponsor/6/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/gold-sponsor/6/avatar.svg?requireActive=false&avatarHeight=225" alt="sponsor"></a>
|
|
21
|
+
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
### Silver Sponsors 🥈
|
|
25
|
+
|
|
26
|
+
<div dir="auto">
|
|
27
|
+
|
|
28
|
+
<a href="https://opencollective.com/rrweb/tiers/silver-sponsor/0/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/silver-sponsor/0/avatar.svg?requireActive=false&avatarHeight=158" alt="sponsor"></a>
|
|
29
|
+
<a href="https://opencollective.com/rrweb/tiers/silver-sponsor/1/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/silver-sponsor/1/avatar.svg?requireActive=false&avatarHeight=158" alt="sponsor"></a>
|
|
30
|
+
<a href="https://opencollective.com/rrweb/tiers/silver-sponsor/2/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/silver-sponsor/2/avatar.svg?requireActive=false&avatarHeight=158" alt="sponsor"></a>
|
|
31
|
+
<a href="https://opencollective.com/rrweb/tiers/silver-sponsor/3/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/silver-sponsor/3/avatar.svg?requireActive=false&avatarHeight=158" alt="sponsor"></a>
|
|
32
|
+
<a href="https://opencollective.com/rrweb/tiers/silver-sponsor/4/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/silver-sponsor/4/avatar.svg?requireActive=false&avatarHeight=158" alt="sponsor"></a>
|
|
33
|
+
<a href="https://opencollective.com/rrweb/tiers/silver-sponsor/5/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/silver-sponsor/5/avatar.svg?requireActive=false&avatarHeight=158" alt="sponsor"></a>
|
|
34
|
+
<a href="https://opencollective.com/rrweb/tiers/silver-sponsor/6/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/silver-sponsor/6/avatar.svg?requireActive=false&avatarHeight=158" alt="sponsor"></a>
|
|
35
|
+
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
### Bronze Sponsors 🥉
|
|
39
|
+
|
|
40
|
+
<div dir="auto">
|
|
41
|
+
|
|
42
|
+
<a href="https://opencollective.com/rrweb/tiers/sponsors/0/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/sponsors/0/avatar.svg?requireActive=false&avatarHeight=70" alt="sponsor"></a>
|
|
43
|
+
<a href="https://opencollective.com/rrweb/tiers/sponsors/1/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/sponsors/1/avatar.svg?requireActive=false&avatarHeight=70" alt="sponsor"></a>
|
|
44
|
+
<a href="https://opencollective.com/rrweb/tiers/sponsors/2/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/sponsors/2/avatar.svg?requireActive=false&avatarHeight=70" alt="sponsor"></a>
|
|
45
|
+
<a href="https://opencollective.com/rrweb/tiers/sponsors/3/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/sponsors/3/avatar.svg?requireActive=false&avatarHeight=70" alt="sponsor"></a>
|
|
46
|
+
<a href="https://opencollective.com/rrweb/tiers/sponsors/4/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/sponsors/4/avatar.svg?requireActive=false&avatarHeight=70" alt="sponsor"></a>
|
|
47
|
+
<a href="https://opencollective.com/rrweb/tiers/sponsors/5/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/sponsors/5/avatar.svg?requireActive=false&avatarHeight=70" alt="sponsor"></a>
|
|
48
|
+
<a href="https://opencollective.com/rrweb/tiers/sponsors/6/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/sponsors/6/avatar.svg?requireActive=false&avatarHeight=70" alt="sponsor"></a>
|
|
49
|
+
<a href="https://opencollective.com/rrweb/tiers/sponsors/7/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/sponsors/7/avatar.svg?requireActive=false&avatarHeight=70" alt="sponsor"></a>
|
|
50
|
+
<a href="https://opencollective.com/rrweb/tiers/sponsors/8/website?requireActive=false" target="_blank"><img src="https://opencollective.com/rrweb/tiers/sponsors/8/avatar.svg?requireActive=false&avatarHeight=70" alt="sponsor"></a>
|
|
51
|
+
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
### Backers
|
|
55
|
+
|
|
56
|
+
<a href="https://opencollective.com/rrweb#sponsor" rel="nofollow"><img src="https://opencollective.com/rrweb/tiers/backers.svg?avatarHeight=36"></a>
|
|
57
|
+
|
|
58
|
+
## Core Team Members
|
|
59
|
+
|
|
60
|
+
<table>
|
|
61
|
+
<tr>
|
|
62
|
+
<td align="center">
|
|
63
|
+
<a href="https://github.com/Yuyz0112">
|
|
64
|
+
<img
|
|
65
|
+
src="https://avatars.githubusercontent.com/u/13651389?s=100"
|
|
66
|
+
width="100px;"
|
|
67
|
+
alt=""
|
|
68
|
+
/>
|
|
69
|
+
<br /><sub><b>Yuyz0112</b></sub>
|
|
70
|
+
<br /><br />
|
|
71
|
+
</a>
|
|
72
|
+
</td>
|
|
73
|
+
<td align="center">
|
|
74
|
+
<a href="https://github.com/YunFeng0817">
|
|
75
|
+
<img
|
|
76
|
+
src="https://avatars.githubusercontent.com/u/27533910?s=100"
|
|
77
|
+
width="100px;"
|
|
78
|
+
alt=""
|
|
79
|
+
/>
|
|
80
|
+
<br /><sub><b>Yun Feng</b></sub>
|
|
81
|
+
<br /><br />
|
|
82
|
+
</a>
|
|
83
|
+
</td>
|
|
84
|
+
<td align="center">
|
|
85
|
+
<a href="https://github.com/eoghanmurray">
|
|
86
|
+
<img
|
|
87
|
+
src="https://avatars.githubusercontent.com/u/156780?s=100"
|
|
88
|
+
width="100px;"
|
|
89
|
+
alt=""
|
|
90
|
+
/>
|
|
91
|
+
<br /><sub><b>eoghanmurray</b></sub>
|
|
92
|
+
<br /><br />
|
|
93
|
+
</a>
|
|
94
|
+
</td>
|
|
95
|
+
<td align="center">
|
|
96
|
+
<a href="https://github.com/Juice10">
|
|
97
|
+
<img
|
|
98
|
+
src="https://avatars.githubusercontent.com/u/4106?s=100"
|
|
99
|
+
width="100px;"
|
|
100
|
+
alt=""
|
|
101
|
+
/>
|
|
102
|
+
<br /><sub><b>Juice10</b></sub>
|
|
103
|
+
<br /><sub>open for rrweb consulting</sub>
|
|
104
|
+
</a>
|
|
105
|
+
</td>
|
|
106
|
+
</tr>
|
|
107
|
+
</table>
|
|
108
|
+
|
|
109
|
+
## Who's using rrweb?
|
|
110
|
+
|
|
111
|
+
<table>
|
|
112
|
+
<tr>
|
|
113
|
+
<td align="center">
|
|
114
|
+
<a href="http://www.smartx.com/" target="_blank">
|
|
115
|
+
<img width="195px" src="https://www.rrweb.io/logos/smartx.png">
|
|
116
|
+
</a>
|
|
117
|
+
</td>
|
|
118
|
+
<td align="center">
|
|
119
|
+
<a href="https://posthog.com?utm_source=rrweb&utm_medium=sponsorship&utm_campaign=open-source-sponsorship" target="_blank">
|
|
120
|
+
<img width="195px" src="https://www.rrweb.io/logos/posthog.png">
|
|
121
|
+
</a>
|
|
122
|
+
</td>
|
|
123
|
+
<td align="center">
|
|
124
|
+
<a href="https://statcounter.com/session-replay/" target="_blank">
|
|
125
|
+
<img width="195px" src="https://statcounter.com/images/logo-statcounter-arc-blue.svg">
|
|
126
|
+
</a>
|
|
127
|
+
</td>
|
|
128
|
+
<td align="center">
|
|
129
|
+
<a href="https://recordonce.com/" target="_blank">
|
|
130
|
+
<img width="195px" alt="Smart screen recording for SaaS" src="https://uploads-ssl.webflow.com/5f3d133183156245630d4446/5f3d1940abe8db8612c23521_Record-Once-logo-554x80px.svg">
|
|
131
|
+
</a>
|
|
132
|
+
</td>
|
|
133
|
+
</tr>
|
|
134
|
+
<tr>
|
|
135
|
+
<td align="center">
|
|
136
|
+
<a href="https://cux.io" target="_blank">
|
|
137
|
+
<img style="padding: 8px" alt="The first ever UX automation tool" width="195px" src="https://cux.io/cux-logo.svg">
|
|
138
|
+
</a>
|
|
139
|
+
</td>
|
|
140
|
+
<td align="center">
|
|
141
|
+
<a href="https://remsupp.com" target="_blank">
|
|
142
|
+
<img style="padding: 8px" alt="Remote Access & Co-Browsing" width="195px" src="https://remsupp.com/images/logo.png">
|
|
143
|
+
</a>
|
|
144
|
+
</td>
|
|
145
|
+
<td align="center">
|
|
146
|
+
<a href="https://highlight.io" target="_blank">
|
|
147
|
+
<img style="padding: 8px" alt="The open source, fullstack Monitoring Platform." width="195px" src="https://github.com/highlight/highlight/raw/main/highlight.io/public/images/logo.png">
|
|
148
|
+
</a>
|
|
149
|
+
</td>
|
|
150
|
+
<td align="center">
|
|
151
|
+
<a href="https://analyzee.io" target="_blank">
|
|
152
|
+
<img style="padding: 8px" alt="Comprehensive data analytics platform that empowers businesses to gain valuable insights and make data-driven decisions." width="195px" src="https://cdn.analyzee.io/assets/analyzee-logo.png">
|
|
153
|
+
</a>
|
|
154
|
+
</td>
|
|
155
|
+
</tr>
|
|
156
|
+
<tr>
|
|
157
|
+
<td align="center">
|
|
158
|
+
<a href="https://requestly.io" target="_blank">
|
|
159
|
+
<img style="padding: 8px" alt="Intercept, Modify, Record & Replay HTTP Requests." width="195px" src="https://github.com/requestly/requestly/assets/16779465/652552db-c867-44cb-9bb5-94a2026e04ca">
|
|
160
|
+
</a>
|
|
161
|
+
</td>
|
|
162
|
+
<td align="center">
|
|
163
|
+
<a href="https://gleap.io" target="_blank">
|
|
164
|
+
<img style="padding: 8px" alt="In-app bug reporting & customer feedback platform." width="195px" src="https://assets-global.website-files.com/6506f3f29c68b1724807619d/6506f56010237164c6306591_GleapLogo.svg">
|
|
165
|
+
</a>
|
|
166
|
+
</td>
|
|
167
|
+
<td align="center">
|
|
168
|
+
<a href="https://uxwizz.com" target="_blank">
|
|
169
|
+
<img style="padding: 8px" alt="Self-hosted website analytics with heatmaps and session recordings." width="195px" src="https://github.com/UXWizz/public-files/raw/main/assets/logo.png">
|
|
170
|
+
</a>
|
|
171
|
+
</td>
|
|
172
|
+
<td align="center">
|
|
173
|
+
<a href="https://www.howdygo.com" target="_blank">
|
|
174
|
+
<img style="padding: 8px" alt="Interactive product demos for small marketing teams" width="195px" src="https://assets-global.website-files.com/650afb446f1dd5bd410f00cc/650b2cec6188ff54dd9b01e1_Logo.svg">
|
|
175
|
+
</a>
|
|
176
|
+
</td>
|
|
177
|
+
</tr>
|
|
178
|
+
</table>
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
declare type BasePrototypeCache = {
|
|
2
|
+
Node: typeof Node.prototype;
|
|
3
|
+
ShadowRoot: typeof ShadowRoot.prototype;
|
|
4
|
+
MutationObserver: typeof MutationObserver.prototype;
|
|
5
|
+
Element: typeof Element.prototype;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export declare function childNodes(n: Node): NodeListOf<Node>;
|
|
9
|
+
|
|
10
|
+
export declare function contains(n: Node, other: Node): boolean;
|
|
11
|
+
|
|
12
|
+
declare const _default: {
|
|
13
|
+
childNodes: typeof childNodes;
|
|
14
|
+
parentNode: typeof parentNode;
|
|
15
|
+
parentElement: typeof parentElement;
|
|
16
|
+
textContent: typeof textContent;
|
|
17
|
+
contains: typeof contains;
|
|
18
|
+
getRootNode: typeof getRootNode;
|
|
19
|
+
host: typeof host;
|
|
20
|
+
styleSheets: typeof styleSheets;
|
|
21
|
+
shadowRoot: typeof shadowRoot;
|
|
22
|
+
querySelector: typeof querySelector;
|
|
23
|
+
querySelectorAll: typeof querySelectorAll;
|
|
24
|
+
mutationObserver: typeof mutationObserverCtor;
|
|
25
|
+
patch: typeof patch;
|
|
26
|
+
};
|
|
27
|
+
export default _default;
|
|
28
|
+
|
|
29
|
+
export declare function getRootNode(n: Node): Node;
|
|
30
|
+
|
|
31
|
+
export declare function getUntaintedAccessor<K extends keyof BasePrototypeCache, T extends keyof BasePrototypeCache[K]>(key: K, instance: BasePrototypeCache[K], accessor: T): BasePrototypeCache[K][T];
|
|
32
|
+
|
|
33
|
+
export declare function getUntaintedMethod<K extends keyof BasePrototypeCache, T extends keyof BasePrototypeCache[K]>(key: K, instance: BasePrototypeCache[K], method: T): BasePrototypeCache[K][T];
|
|
34
|
+
|
|
35
|
+
export declare function getUntaintedPrototype<T extends keyof BasePrototypeCache>(key: T): BasePrototypeCache[T];
|
|
36
|
+
|
|
37
|
+
export declare function host(n: ShadowRoot): Element | null;
|
|
38
|
+
|
|
39
|
+
export declare const isAngularZonePresent: () => boolean;
|
|
40
|
+
|
|
41
|
+
export declare function mutationObserverCtor(): (typeof MutationObserver)['prototype']['constructor'];
|
|
42
|
+
|
|
43
|
+
export declare function parentElement(n: Node): HTMLElement | null;
|
|
44
|
+
|
|
45
|
+
export declare function parentNode(n: Node): ParentNode | null;
|
|
46
|
+
|
|
47
|
+
export declare function patch(source: {
|
|
48
|
+
[key: string]: any;
|
|
49
|
+
}, name: string, replacement: (...args: unknown[]) => unknown): () => void;
|
|
50
|
+
|
|
51
|
+
export declare function querySelector(n: Element, selectors: string): Element | null;
|
|
52
|
+
|
|
53
|
+
export declare function querySelectorAll(n: Element, selectors: string): NodeListOf<Element>;
|
|
54
|
+
|
|
55
|
+
export declare function shadowRoot(n: Node): ShadowRoot | null;
|
|
56
|
+
|
|
57
|
+
export declare function styleSheets(n: ShadowRoot): StyleSheetList;
|
|
58
|
+
|
|
59
|
+
export declare function textContent(n: Node): string | null;
|
|
60
|
+
|
|
61
|
+
export { }
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
declare type BasePrototypeCache = {
|
|
2
|
+
Node: typeof Node.prototype;
|
|
3
|
+
ShadowRoot: typeof ShadowRoot.prototype;
|
|
4
|
+
MutationObserver: typeof MutationObserver.prototype;
|
|
5
|
+
Element: typeof Element.prototype;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export declare function childNodes(n: Node): NodeListOf<Node>;
|
|
9
|
+
|
|
10
|
+
export declare function contains(n: Node, other: Node): boolean;
|
|
11
|
+
|
|
12
|
+
declare const _default: {
|
|
13
|
+
childNodes: typeof childNodes;
|
|
14
|
+
parentNode: typeof parentNode;
|
|
15
|
+
parentElement: typeof parentElement;
|
|
16
|
+
textContent: typeof textContent;
|
|
17
|
+
contains: typeof contains;
|
|
18
|
+
getRootNode: typeof getRootNode;
|
|
19
|
+
host: typeof host;
|
|
20
|
+
styleSheets: typeof styleSheets;
|
|
21
|
+
shadowRoot: typeof shadowRoot;
|
|
22
|
+
querySelector: typeof querySelector;
|
|
23
|
+
querySelectorAll: typeof querySelectorAll;
|
|
24
|
+
mutationObserver: typeof mutationObserverCtor;
|
|
25
|
+
patch: typeof patch;
|
|
26
|
+
};
|
|
27
|
+
export default _default;
|
|
28
|
+
|
|
29
|
+
export declare function getRootNode(n: Node): Node;
|
|
30
|
+
|
|
31
|
+
export declare function getUntaintedAccessor<K extends keyof BasePrototypeCache, T extends keyof BasePrototypeCache[K]>(key: K, instance: BasePrototypeCache[K], accessor: T): BasePrototypeCache[K][T];
|
|
32
|
+
|
|
33
|
+
export declare function getUntaintedMethod<K extends keyof BasePrototypeCache, T extends keyof BasePrototypeCache[K]>(key: K, instance: BasePrototypeCache[K], method: T): BasePrototypeCache[K][T];
|
|
34
|
+
|
|
35
|
+
export declare function getUntaintedPrototype<T extends keyof BasePrototypeCache>(key: T): BasePrototypeCache[T];
|
|
36
|
+
|
|
37
|
+
export declare function host(n: ShadowRoot): Element | null;
|
|
38
|
+
|
|
39
|
+
export declare const isAngularZonePresent: () => boolean;
|
|
40
|
+
|
|
41
|
+
export declare function mutationObserverCtor(): (typeof MutationObserver)['prototype']['constructor'];
|
|
42
|
+
|
|
43
|
+
export declare function parentElement(n: Node): HTMLElement | null;
|
|
44
|
+
|
|
45
|
+
export declare function parentNode(n: Node): ParentNode | null;
|
|
46
|
+
|
|
47
|
+
export declare function patch(source: {
|
|
48
|
+
[key: string]: any;
|
|
49
|
+
}, name: string, replacement: (...args: unknown[]) => unknown): () => void;
|
|
50
|
+
|
|
51
|
+
export declare function querySelector(n: Element, selectors: string): Element | null;
|
|
52
|
+
|
|
53
|
+
export declare function querySelectorAll(n: Element, selectors: string): NodeListOf<Element>;
|
|
54
|
+
|
|
55
|
+
export declare function shadowRoot(n: Node): ShadowRoot | null;
|
|
56
|
+
|
|
57
|
+
export declare function styleSheets(n: ShadowRoot): StyleSheetList;
|
|
58
|
+
|
|
59
|
+
export declare function textContent(n: Node): string | null;
|
|
60
|
+
|
|
61
|
+
export { }
|
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const testableAccessors = {
|
|
4
|
+
Node: ["childNodes", "parentNode", "parentElement", "textContent"],
|
|
5
|
+
ShadowRoot: ["host", "styleSheets"],
|
|
6
|
+
Element: ["shadowRoot", "querySelector", "querySelectorAll"],
|
|
7
|
+
MutationObserver: []
|
|
8
|
+
};
|
|
9
|
+
const testableMethods = {
|
|
10
|
+
Node: ["contains", "getRootNode"],
|
|
11
|
+
ShadowRoot: ["getSelection"],
|
|
12
|
+
Element: [],
|
|
13
|
+
MutationObserver: ["constructor"]
|
|
14
|
+
};
|
|
15
|
+
const untaintedBasePrototype = {};
|
|
16
|
+
const isAngularZonePresent = () => {
|
|
17
|
+
return !!globalThis.Zone;
|
|
18
|
+
};
|
|
19
|
+
function getUntaintedPrototype(key) {
|
|
20
|
+
if (untaintedBasePrototype[key])
|
|
21
|
+
return untaintedBasePrototype[key];
|
|
22
|
+
const defaultObj = globalThis[key];
|
|
23
|
+
const defaultPrototype = defaultObj.prototype;
|
|
24
|
+
const accessorNames = key in testableAccessors ? testableAccessors[key] : void 0;
|
|
25
|
+
const isUntaintedAccessors = Boolean(
|
|
26
|
+
accessorNames && // @ts-expect-error 2345
|
|
27
|
+
accessorNames.every(
|
|
28
|
+
(accessor) => {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
return Boolean(
|
|
31
|
+
(_b = (_a = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) == null ? void 0 : _a.get) == null ? void 0 : _b.toString().includes("[native code]")
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
const methodNames = key in testableMethods ? testableMethods[key] : void 0;
|
|
37
|
+
const isUntaintedMethods = Boolean(
|
|
38
|
+
methodNames && methodNames.every(
|
|
39
|
+
// @ts-expect-error 2345
|
|
40
|
+
(method) => {
|
|
41
|
+
var _a;
|
|
42
|
+
return typeof defaultPrototype[method] === "function" && ((_a = defaultPrototype[method]) == null ? void 0 : _a.toString().includes("[native code]"));
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
if (isUntaintedAccessors && isUntaintedMethods && !isAngularZonePresent()) {
|
|
47
|
+
untaintedBasePrototype[key] = defaultObj.prototype;
|
|
48
|
+
return defaultObj.prototype;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const iframeEl = document.createElement("iframe");
|
|
52
|
+
document.body.appendChild(iframeEl);
|
|
53
|
+
const win = iframeEl.contentWindow;
|
|
54
|
+
if (!win) return defaultObj.prototype;
|
|
55
|
+
const untaintedObject = win[key].prototype;
|
|
56
|
+
document.body.removeChild(iframeEl);
|
|
57
|
+
if (!untaintedObject) return defaultPrototype;
|
|
58
|
+
return untaintedBasePrototype[key] = untaintedObject;
|
|
59
|
+
} catch {
|
|
60
|
+
return defaultPrototype;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const untaintedAccessorCache = {};
|
|
64
|
+
function getUntaintedAccessor(key, instance, accessor) {
|
|
65
|
+
var _a;
|
|
66
|
+
const cacheKey = `${key}.${String(accessor)}`;
|
|
67
|
+
if (untaintedAccessorCache[cacheKey])
|
|
68
|
+
return untaintedAccessorCache[cacheKey].call(
|
|
69
|
+
instance
|
|
70
|
+
);
|
|
71
|
+
const untaintedPrototype = getUntaintedPrototype(key);
|
|
72
|
+
const untaintedAccessor = (_a = Object.getOwnPropertyDescriptor(
|
|
73
|
+
untaintedPrototype,
|
|
74
|
+
accessor
|
|
75
|
+
)) == null ? void 0 : _a.get;
|
|
76
|
+
if (!untaintedAccessor) return instance[accessor];
|
|
77
|
+
untaintedAccessorCache[cacheKey] = untaintedAccessor;
|
|
78
|
+
return untaintedAccessor.call(instance);
|
|
79
|
+
}
|
|
80
|
+
const untaintedMethodCache = {};
|
|
81
|
+
function getUntaintedMethod(key, instance, method) {
|
|
82
|
+
const cacheKey = `${key}.${String(method)}`;
|
|
83
|
+
if (untaintedMethodCache[cacheKey])
|
|
84
|
+
return untaintedMethodCache[cacheKey].bind(
|
|
85
|
+
instance
|
|
86
|
+
);
|
|
87
|
+
const untaintedPrototype = getUntaintedPrototype(key);
|
|
88
|
+
const untaintedMethod = untaintedPrototype[method];
|
|
89
|
+
if (typeof untaintedMethod !== "function") return instance[method];
|
|
90
|
+
untaintedMethodCache[cacheKey] = untaintedMethod;
|
|
91
|
+
return untaintedMethod.bind(instance);
|
|
92
|
+
}
|
|
93
|
+
function childNodes(n) {
|
|
94
|
+
return getUntaintedAccessor("Node", n, "childNodes");
|
|
95
|
+
}
|
|
96
|
+
function parentNode(n) {
|
|
97
|
+
return getUntaintedAccessor("Node", n, "parentNode");
|
|
98
|
+
}
|
|
99
|
+
function parentElement(n) {
|
|
100
|
+
return getUntaintedAccessor("Node", n, "parentElement");
|
|
101
|
+
}
|
|
102
|
+
function textContent(n) {
|
|
103
|
+
return getUntaintedAccessor("Node", n, "textContent");
|
|
104
|
+
}
|
|
105
|
+
function contains(n, other) {
|
|
106
|
+
return getUntaintedMethod("Node", n, "contains")(other);
|
|
107
|
+
}
|
|
108
|
+
function getRootNode(n) {
|
|
109
|
+
return getUntaintedMethod("Node", n, "getRootNode")();
|
|
110
|
+
}
|
|
111
|
+
function host(n) {
|
|
112
|
+
if (!n || !("host" in n)) return null;
|
|
113
|
+
return getUntaintedAccessor("ShadowRoot", n, "host");
|
|
114
|
+
}
|
|
115
|
+
function styleSheets(n) {
|
|
116
|
+
return n.styleSheets;
|
|
117
|
+
}
|
|
118
|
+
function shadowRoot(n) {
|
|
119
|
+
if (!n || !("shadowRoot" in n)) return null;
|
|
120
|
+
return getUntaintedAccessor("Element", n, "shadowRoot");
|
|
121
|
+
}
|
|
122
|
+
function querySelector(n, selectors) {
|
|
123
|
+
return getUntaintedAccessor("Element", n, "querySelector")(selectors);
|
|
124
|
+
}
|
|
125
|
+
function querySelectorAll(n, selectors) {
|
|
126
|
+
return getUntaintedAccessor("Element", n, "querySelectorAll")(selectors);
|
|
127
|
+
}
|
|
128
|
+
function mutationObserverCtor() {
|
|
129
|
+
return getUntaintedPrototype("MutationObserver").constructor;
|
|
130
|
+
}
|
|
131
|
+
function patch(source, name, replacement) {
|
|
132
|
+
try {
|
|
133
|
+
if (!(name in source)) {
|
|
134
|
+
return () => {
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const original = source[name];
|
|
138
|
+
const wrapped = replacement(original);
|
|
139
|
+
if (typeof wrapped === "function") {
|
|
140
|
+
wrapped.prototype = wrapped.prototype || {};
|
|
141
|
+
Object.defineProperties(wrapped, {
|
|
142
|
+
__rrweb_original__: {
|
|
143
|
+
enumerable: false,
|
|
144
|
+
value: original
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
source[name] = wrapped;
|
|
149
|
+
return () => {
|
|
150
|
+
source[name] = original;
|
|
151
|
+
};
|
|
152
|
+
} catch {
|
|
153
|
+
return () => {
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const index = {
|
|
158
|
+
childNodes,
|
|
159
|
+
parentNode,
|
|
160
|
+
parentElement,
|
|
161
|
+
textContent,
|
|
162
|
+
contains,
|
|
163
|
+
getRootNode,
|
|
164
|
+
host,
|
|
165
|
+
styleSheets,
|
|
166
|
+
shadowRoot,
|
|
167
|
+
querySelector,
|
|
168
|
+
querySelectorAll,
|
|
169
|
+
mutationObserver: mutationObserverCtor,
|
|
170
|
+
patch
|
|
171
|
+
};
|
|
172
|
+
exports.childNodes = childNodes;
|
|
173
|
+
exports.contains = contains;
|
|
174
|
+
exports.default = index;
|
|
175
|
+
exports.getRootNode = getRootNode;
|
|
176
|
+
exports.getUntaintedAccessor = getUntaintedAccessor;
|
|
177
|
+
exports.getUntaintedMethod = getUntaintedMethod;
|
|
178
|
+
exports.getUntaintedPrototype = getUntaintedPrototype;
|
|
179
|
+
exports.host = host;
|
|
180
|
+
exports.isAngularZonePresent = isAngularZonePresent;
|
|
181
|
+
exports.mutationObserverCtor = mutationObserverCtor;
|
|
182
|
+
exports.parentElement = parentElement;
|
|
183
|
+
exports.parentNode = parentNode;
|
|
184
|
+
exports.patch = patch;
|
|
185
|
+
exports.querySelector = querySelector;
|
|
186
|
+
exports.querySelectorAll = querySelectorAll;
|
|
187
|
+
exports.shadowRoot = shadowRoot;
|
|
188
|
+
exports.styleSheets = styleSheets;
|
|
189
|
+
exports.textContent = textContent;
|
|
190
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","sources":["../src/index.ts"],"sourcesContent":["type PrototypeOwner = Node | ShadowRoot | MutationObserver | Element;\ntype TypeofPrototypeOwner =\n | typeof Node\n | typeof ShadowRoot\n | typeof MutationObserver\n | typeof Element;\n\ntype BasePrototypeCache = {\n Node: typeof Node.prototype;\n ShadowRoot: typeof ShadowRoot.prototype;\n MutationObserver: typeof MutationObserver.prototype;\n Element: typeof Element.prototype;\n};\n\nconst testableAccessors = {\n Node: ['childNodes', 'parentNode', 'parentElement', 'textContent'] as const,\n ShadowRoot: ['host', 'styleSheets'] as const,\n Element: ['shadowRoot', 'querySelector', 'querySelectorAll'] as const,\n MutationObserver: [] as const,\n} as const;\n\nconst testableMethods = {\n Node: ['contains', 'getRootNode'] as const,\n ShadowRoot: ['getSelection'],\n Element: [],\n MutationObserver: ['constructor'],\n} as const;\n\nconst untaintedBasePrototype: Partial<BasePrototypeCache> = {};\n\n/*\n When angular patches things - particularly the MutationObserver -\n they pass the `isNativeFunction` check\n That then causes performance issues\n because Angular's change detection\n doesn't like sharing a mutation observer\n Checking for the presence of the Zone object\n on global is a good-enough proxy for Angular\n to cover most cases\n (you can configure zone.js to have a different name\n on the global object and should then manually run rrweb\n outside the Zone)\n */\nexport const isAngularZonePresent = (): boolean => {\n return !!(globalThis as { Zone?: unknown }).Zone;\n};\n\nexport function getUntaintedPrototype<T extends keyof BasePrototypeCache>(\n key: T,\n): BasePrototypeCache[T] {\n if (untaintedBasePrototype[key])\n return untaintedBasePrototype[key] as BasePrototypeCache[T];\n\n const defaultObj = globalThis[key] as TypeofPrototypeOwner;\n const defaultPrototype = defaultObj.prototype as BasePrototypeCache[T];\n\n // use list of testable accessors to check if the prototype is tainted\n const accessorNames =\n key in testableAccessors ? testableAccessors[key] : undefined;\n const isUntaintedAccessors = Boolean(\n accessorNames &&\n // @ts-expect-error 2345\n accessorNames.every((accessor: keyof typeof defaultPrototype) =>\n Boolean(\n Object.getOwnPropertyDescriptor(defaultPrototype, accessor)\n ?.get?.toString()\n .includes('[native code]'),\n ),\n ),\n );\n\n const methodNames = key in testableMethods ? testableMethods[key] : undefined;\n const isUntaintedMethods = Boolean(\n methodNames &&\n methodNames.every(\n // @ts-expect-error 2345\n (method: keyof typeof defaultPrototype) =>\n typeof defaultPrototype[method] === 'function' &&\n defaultPrototype[method]?.toString().includes('[native code]'),\n ),\n );\n\n if (isUntaintedAccessors && isUntaintedMethods && !isAngularZonePresent()) {\n untaintedBasePrototype[key] = defaultObj.prototype as BasePrototypeCache[T];\n return defaultObj.prototype as BasePrototypeCache[T];\n }\n\n try {\n const iframeEl = document.createElement('iframe');\n document.body.appendChild(iframeEl);\n const win = iframeEl.contentWindow;\n if (!win) return defaultObj.prototype as BasePrototypeCache[T];\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n const untaintedObject = (win as any)[key]\n .prototype as BasePrototypeCache[T];\n // cleanup\n document.body.removeChild(iframeEl);\n\n if (!untaintedObject) return defaultPrototype;\n\n return (untaintedBasePrototype[key] = untaintedObject);\n } catch {\n return defaultPrototype;\n }\n}\n\nconst untaintedAccessorCache: Record<\n string,\n (this: PrototypeOwner, ...args: unknown[]) => unknown\n> = {};\n\nexport function getUntaintedAccessor<\n K extends keyof BasePrototypeCache,\n T extends keyof BasePrototypeCache[K],\n>(\n key: K,\n instance: BasePrototypeCache[K],\n accessor: T,\n): BasePrototypeCache[K][T] {\n const cacheKey = `${key}.${String(accessor)}`;\n if (untaintedAccessorCache[cacheKey])\n return untaintedAccessorCache[cacheKey].call(\n instance,\n ) as BasePrototypeCache[K][T];\n\n const untaintedPrototype = getUntaintedPrototype(key);\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const untaintedAccessor = Object.getOwnPropertyDescriptor(\n untaintedPrototype,\n accessor,\n )?.get;\n\n if (!untaintedAccessor) return instance[accessor];\n\n untaintedAccessorCache[cacheKey] = untaintedAccessor;\n\n return untaintedAccessor.call(instance) as BasePrototypeCache[K][T];\n}\n\ntype BaseMethod<K extends keyof BasePrototypeCache> = (\n this: BasePrototypeCache[K],\n ...args: unknown[]\n) => unknown;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst untaintedMethodCache: Record<string, BaseMethod<any>> = {};\nexport function getUntaintedMethod<\n K extends keyof BasePrototypeCache,\n T extends keyof BasePrototypeCache[K],\n>(\n key: K,\n instance: BasePrototypeCache[K],\n method: T,\n): BasePrototypeCache[K][T] {\n const cacheKey = `${key}.${String(method)}`;\n if (untaintedMethodCache[cacheKey])\n return untaintedMethodCache[cacheKey].bind(\n instance,\n ) as BasePrototypeCache[K][T];\n\n const untaintedPrototype = getUntaintedPrototype(key);\n const untaintedMethod = untaintedPrototype[method];\n\n if (typeof untaintedMethod !== 'function') return instance[method];\n\n untaintedMethodCache[cacheKey] = untaintedMethod as BaseMethod<K>;\n\n return untaintedMethod.bind(instance) as BasePrototypeCache[K][T];\n}\n\nexport function childNodes(n: Node): NodeListOf<Node> {\n return getUntaintedAccessor('Node', n, 'childNodes');\n}\n\nexport function parentNode(n: Node): ParentNode | null {\n return getUntaintedAccessor('Node', n, 'parentNode');\n}\n\nexport function parentElement(n: Node): HTMLElement | null {\n return getUntaintedAccessor('Node', n, 'parentElement');\n}\n\nexport function textContent(n: Node): string | null {\n return getUntaintedAccessor('Node', n, 'textContent');\n}\n\nexport function contains(n: Node, other: Node): boolean {\n return getUntaintedMethod('Node', n, 'contains')(other);\n}\n\nexport function getRootNode(n: Node): Node {\n return getUntaintedMethod('Node', n, 'getRootNode')();\n}\n\nexport function host(n: ShadowRoot): Element | null {\n if (!n || !('host' in n)) return null;\n return getUntaintedAccessor('ShadowRoot', n, 'host');\n}\n\nexport function styleSheets(n: ShadowRoot): StyleSheetList {\n return n.styleSheets;\n}\n\nexport function shadowRoot(n: Node): ShadowRoot | null {\n if (!n || !('shadowRoot' in n)) return null;\n return getUntaintedAccessor('Element', n as Element, 'shadowRoot');\n}\n\nexport function querySelector(n: Element, selectors: string): Element | null {\n return getUntaintedAccessor('Element', n, 'querySelector')(selectors);\n}\n\nexport function querySelectorAll(\n n: Element,\n selectors: string,\n): NodeListOf<Element> {\n return getUntaintedAccessor('Element', n, 'querySelectorAll')(selectors);\n}\n\nexport function mutationObserverCtor(): (typeof MutationObserver)['prototype']['constructor'] {\n return getUntaintedPrototype('MutationObserver').constructor;\n}\n\n// copy from https://github.com/getsentry/sentry-javascript/blob/b2109071975af8bf0316d3b5b38f519bdaf5dc15/packages/utils/src/object.ts\nexport function patch(\n source: { [key: string]: any },\n name: string,\n replacement: (...args: unknown[]) => unknown,\n): () => void {\n try {\n if (!(name in source)) {\n return () => {\n //\n };\n }\n\n const original = source[name] as () => unknown;\n const wrapped = replacement(original);\n\n // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work\n // otherwise it'll throw \"TypeError: Object.defineProperties called on non-object\"\n if (typeof wrapped === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n wrapped.prototype = wrapped.prototype || {};\n Object.defineProperties(wrapped, {\n __rrweb_original__: {\n enumerable: false,\n value: original,\n },\n });\n }\n\n source[name] = wrapped;\n\n return () => {\n source[name] = original;\n };\n } catch {\n return () => {\n //\n };\n // This can throw if multiple fill happens on a global object like XMLHttpRequest\n // Fixes https://github.com/getsentry/sentry-javascript/issues/2043\n }\n}\n\nexport default {\n childNodes,\n parentNode,\n parentElement,\n textContent,\n contains,\n getRootNode,\n host,\n styleSheets,\n shadowRoot,\n querySelector,\n querySelectorAll,\n mutationObserver: mutationObserverCtor,\n patch,\n};\n"],"names":[],"mappings":";;AAcA,MAAM,oBAAoB;AAAA,EACxB,MAAM,CAAC,cAAc,cAAc,iBAAiB,aAAa;AAAA,EACjE,YAAY,CAAC,QAAQ,aAAa;AAAA,EAClC,SAAS,CAAC,cAAc,iBAAiB,kBAAkB;AAAA,EAC3D,kBAAkB,CAAC;AACrB;AAEA,MAAM,kBAAkB;AAAA,EACtB,MAAM,CAAC,YAAY,aAAa;AAAA,EAChC,YAAY,CA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AAkB;AAAA,EAClB;AACF;;;;;;;;;;;;;;;;;;;"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
const testableAccessors = {
|
|
2
|
+
Node: ["childNodes", "parentNode", "parentElement", "textContent"],
|
|
3
|
+
ShadowRoot: ["host", "styleSheets"],
|
|
4
|
+
Element: ["shadowRoot", "querySelector", "querySelectorAll"],
|
|
5
|
+
MutationObserver: []
|
|
6
|
+
};
|
|
7
|
+
const testableMethods = {
|
|
8
|
+
Node: ["contains", "getRootNode"],
|
|
9
|
+
ShadowRoot: ["getSelection"],
|
|
10
|
+
Element: [],
|
|
11
|
+
MutationObserver: ["constructor"]
|
|
12
|
+
};
|
|
13
|
+
const untaintedBasePrototype = {};
|
|
14
|
+
const isAngularZonePresent = () => {
|
|
15
|
+
return !!globalThis.Zone;
|
|
16
|
+
};
|
|
17
|
+
function getUntaintedPrototype(key) {
|
|
18
|
+
if (untaintedBasePrototype[key])
|
|
19
|
+
return untaintedBasePrototype[key];
|
|
20
|
+
const defaultObj = globalThis[key];
|
|
21
|
+
const defaultPrototype = defaultObj.prototype;
|
|
22
|
+
const accessorNames = key in testableAccessors ? testableAccessors[key] : void 0;
|
|
23
|
+
const isUntaintedAccessors = Boolean(
|
|
24
|
+
accessorNames && // @ts-expect-error 2345
|
|
25
|
+
accessorNames.every(
|
|
26
|
+
(accessor) => {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
return Boolean(
|
|
29
|
+
(_b = (_a = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) == null ? void 0 : _a.get) == null ? void 0 : _b.toString().includes("[native code]")
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
);
|
|
34
|
+
const methodNames = key in testableMethods ? testableMethods[key] : void 0;
|
|
35
|
+
const isUntaintedMethods = Boolean(
|
|
36
|
+
methodNames && methodNames.every(
|
|
37
|
+
// @ts-expect-error 2345
|
|
38
|
+
(method) => {
|
|
39
|
+
var _a;
|
|
40
|
+
return typeof defaultPrototype[method] === "function" && ((_a = defaultPrototype[method]) == null ? void 0 : _a.toString().includes("[native code]"));
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
if (isUntaintedAccessors && isUntaintedMethods && !isAngularZonePresent()) {
|
|
45
|
+
untaintedBasePrototype[key] = defaultObj.prototype;
|
|
46
|
+
return defaultObj.prototype;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const iframeEl = document.createElement("iframe");
|
|
50
|
+
document.body.appendChild(iframeEl);
|
|
51
|
+
const win = iframeEl.contentWindow;
|
|
52
|
+
if (!win) return defaultObj.prototype;
|
|
53
|
+
const untaintedObject = win[key].prototype;
|
|
54
|
+
document.body.removeChild(iframeEl);
|
|
55
|
+
if (!untaintedObject) return defaultPrototype;
|
|
56
|
+
return untaintedBasePrototype[key] = untaintedObject;
|
|
57
|
+
} catch {
|
|
58
|
+
return defaultPrototype;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const untaintedAccessorCache = {};
|
|
62
|
+
function getUntaintedAccessor(key, instance, accessor) {
|
|
63
|
+
var _a;
|
|
64
|
+
const cacheKey = `${key}.${String(accessor)}`;
|
|
65
|
+
if (untaintedAccessorCache[cacheKey])
|
|
66
|
+
return untaintedAccessorCache[cacheKey].call(
|
|
67
|
+
instance
|
|
68
|
+
);
|
|
69
|
+
const untaintedPrototype = getUntaintedPrototype(key);
|
|
70
|
+
const untaintedAccessor = (_a = Object.getOwnPropertyDescriptor(
|
|
71
|
+
untaintedPrototype,
|
|
72
|
+
accessor
|
|
73
|
+
)) == null ? void 0 : _a.get;
|
|
74
|
+
if (!untaintedAccessor) return instance[accessor];
|
|
75
|
+
untaintedAccessorCache[cacheKey] = untaintedAccessor;
|
|
76
|
+
return untaintedAccessor.call(instance);
|
|
77
|
+
}
|
|
78
|
+
const untaintedMethodCache = {};
|
|
79
|
+
function getUntaintedMethod(key, instance, method) {
|
|
80
|
+
const cacheKey = `${key}.${String(method)}`;
|
|
81
|
+
if (untaintedMethodCache[cacheKey])
|
|
82
|
+
return untaintedMethodCache[cacheKey].bind(
|
|
83
|
+
instance
|
|
84
|
+
);
|
|
85
|
+
const untaintedPrototype = getUntaintedPrototype(key);
|
|
86
|
+
const untaintedMethod = untaintedPrototype[method];
|
|
87
|
+
if (typeof untaintedMethod !== "function") return instance[method];
|
|
88
|
+
untaintedMethodCache[cacheKey] = untaintedMethod;
|
|
89
|
+
return untaintedMethod.bind(instance);
|
|
90
|
+
}
|
|
91
|
+
function childNodes(n) {
|
|
92
|
+
return getUntaintedAccessor("Node", n, "childNodes");
|
|
93
|
+
}
|
|
94
|
+
function parentNode(n) {
|
|
95
|
+
return getUntaintedAccessor("Node", n, "parentNode");
|
|
96
|
+
}
|
|
97
|
+
function parentElement(n) {
|
|
98
|
+
return getUntaintedAccessor("Node", n, "parentElement");
|
|
99
|
+
}
|
|
100
|
+
function textContent(n) {
|
|
101
|
+
return getUntaintedAccessor("Node", n, "textContent");
|
|
102
|
+
}
|
|
103
|
+
function contains(n, other) {
|
|
104
|
+
return getUntaintedMethod("Node", n, "contains")(other);
|
|
105
|
+
}
|
|
106
|
+
function getRootNode(n) {
|
|
107
|
+
return getUntaintedMethod("Node", n, "getRootNode")();
|
|
108
|
+
}
|
|
109
|
+
function host(n) {
|
|
110
|
+
if (!n || !("host" in n)) return null;
|
|
111
|
+
return getUntaintedAccessor("ShadowRoot", n, "host");
|
|
112
|
+
}
|
|
113
|
+
function styleSheets(n) {
|
|
114
|
+
return n.styleSheets;
|
|
115
|
+
}
|
|
116
|
+
function shadowRoot(n) {
|
|
117
|
+
if (!n || !("shadowRoot" in n)) return null;
|
|
118
|
+
return getUntaintedAccessor("Element", n, "shadowRoot");
|
|
119
|
+
}
|
|
120
|
+
function querySelector(n, selectors) {
|
|
121
|
+
return getUntaintedAccessor("Element", n, "querySelector")(selectors);
|
|
122
|
+
}
|
|
123
|
+
function querySelectorAll(n, selectors) {
|
|
124
|
+
return getUntaintedAccessor("Element", n, "querySelectorAll")(selectors);
|
|
125
|
+
}
|
|
126
|
+
function mutationObserverCtor() {
|
|
127
|
+
return getUntaintedPrototype("MutationObserver").constructor;
|
|
128
|
+
}
|
|
129
|
+
function patch(source, name, replacement) {
|
|
130
|
+
try {
|
|
131
|
+
if (!(name in source)) {
|
|
132
|
+
return () => {
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const original = source[name];
|
|
136
|
+
const wrapped = replacement(original);
|
|
137
|
+
if (typeof wrapped === "function") {
|
|
138
|
+
wrapped.prototype = wrapped.prototype || {};
|
|
139
|
+
Object.defineProperties(wrapped, {
|
|
140
|
+
__rrweb_original__: {
|
|
141
|
+
enumerable: false,
|
|
142
|
+
value: original
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
source[name] = wrapped;
|
|
147
|
+
return () => {
|
|
148
|
+
source[name] = original;
|
|
149
|
+
};
|
|
150
|
+
} catch {
|
|
151
|
+
return () => {
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const index = {
|
|
156
|
+
childNodes,
|
|
157
|
+
parentNode,
|
|
158
|
+
parentElement,
|
|
159
|
+
textContent,
|
|
160
|
+
contains,
|
|
161
|
+
getRootNode,
|
|
162
|
+
host,
|
|
163
|
+
styleSheets,
|
|
164
|
+
shadowRoot,
|
|
165
|
+
querySelector,
|
|
166
|
+
querySelectorAll,
|
|
167
|
+
mutationObserver: mutationObserverCtor,
|
|
168
|
+
patch
|
|
169
|
+
};
|
|
170
|
+
export {
|
|
171
|
+
childNodes,
|
|
172
|
+
contains,
|
|
173
|
+
index as default,
|
|
174
|
+
getRootNode,
|
|
175
|
+
getUntaintedAccessor,
|
|
176
|
+
getUntaintedMethod,
|
|
177
|
+
getUntaintedPrototype,
|
|
178
|
+
host,
|
|
179
|
+
isAngularZonePresent,
|
|
180
|
+
mutationObserverCtor,
|
|
181
|
+
parentElement,
|
|
182
|
+
parentNode,
|
|
183
|
+
patch,
|
|
184
|
+
querySelector,
|
|
185
|
+
querySelectorAll,
|
|
186
|
+
shadowRoot,
|
|
187
|
+
styleSheets,
|
|
188
|
+
textContent
|
|
189
|
+
};
|
|
190
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../src/index.ts"],"sourcesContent":["type PrototypeOwner = Node | ShadowRoot | MutationObserver | Element;\ntype TypeofPrototypeOwner =\n | typeof Node\n | typeof ShadowRoot\n | typeof MutationObserver\n | typeof Element;\n\ntype BasePrototypeCache = {\n Node: typeof Node.prototype;\n ShadowRoot: typeof ShadowRoot.prototype;\n MutationObserver: typeof MutationObserver.prototype;\n Element: typeof Element.prototype;\n};\n\nconst testableAccessors = {\n Node: ['childNodes', 'parentNode', 'parentElement', 'textContent'] as const,\n ShadowRoot: ['host', 'styleSheets'] as const,\n Element: ['shadowRoot', 'querySelector', 'querySelectorAll'] as const,\n MutationObserver: [] as const,\n} as const;\n\nconst testableMethods = {\n Node: ['contains', 'getRootNode'] as const,\n ShadowRoot: ['getSelection'],\n Element: [],\n MutationObserver: ['constructor'],\n} as const;\n\nconst untaintedBasePrototype: Partial<BasePrototypeCache> = {};\n\n/*\n When angular patches things - particularly the MutationObserver -\n they pass the `isNativeFunction` check\n That then causes performance issues\n because Angular's change detection\n doesn't like sharing a mutation observer\n Checking for the presence of the Zone object\n on global is a good-enough proxy for Angular\n to cover most cases\n (you can configure zone.js to have a different name\n on the global object and should then manually run rrweb\n outside the Zone)\n */\nexport const isAngularZonePresent = (): boolean => {\n return !!(globalThis as { Zone?: unknown }).Zone;\n};\n\nexport function getUntaintedPrototype<T extends keyof BasePrototypeCache>(\n key: T,\n): BasePrototypeCache[T] {\n if (untaintedBasePrototype[key])\n return untaintedBasePrototype[key] as BasePrototypeCache[T];\n\n const defaultObj = globalThis[key] as TypeofPrototypeOwner;\n const defaultPrototype = defaultObj.prototype as BasePrototypeCache[T];\n\n // use list of testable accessors to check if the prototype is tainted\n const accessorNames =\n key in testableAccessors ? testableAccessors[key] : undefined;\n const isUntaintedAccessors = Boolean(\n accessorNames &&\n // @ts-expect-error 2345\n accessorNames.every((accessor: keyof typeof defaultPrototype) =>\n Boolean(\n Object.getOwnPropertyDescriptor(defaultPrototype, accessor)\n ?.get?.toString()\n .includes('[native code]'),\n ),\n ),\n );\n\n const methodNames = key in testableMethods ? testableMethods[key] : undefined;\n const isUntaintedMethods = Boolean(\n methodNames &&\n methodNames.every(\n // @ts-expect-error 2345\n (method: keyof typeof defaultPrototype) =>\n typeof defaultPrototype[method] === 'function' &&\n defaultPrototype[method]?.toString().includes('[native code]'),\n ),\n );\n\n if (isUntaintedAccessors && isUntaintedMethods && !isAngularZonePresent()) {\n untaintedBasePrototype[key] = defaultObj.prototype as BasePrototypeCache[T];\n return defaultObj.prototype as BasePrototypeCache[T];\n }\n\n try {\n const iframeEl = document.createElement('iframe');\n document.body.appendChild(iframeEl);\n const win = iframeEl.contentWindow;\n if (!win) return defaultObj.prototype as BasePrototypeCache[T];\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n const untaintedObject = (win as any)[key]\n .prototype as BasePrototypeCache[T];\n // cleanup\n document.body.removeChild(iframeEl);\n\n if (!untaintedObject) return defaultPrototype;\n\n return (untaintedBasePrototype[key] = untaintedObject);\n } catch {\n return defaultPrototype;\n }\n}\n\nconst untaintedAccessorCache: Record<\n string,\n (this: PrototypeOwner, ...args: unknown[]) => unknown\n> = {};\n\nexport function getUntaintedAccessor<\n K extends keyof BasePrototypeCache,\n T extends keyof BasePrototypeCache[K],\n>(\n key: K,\n instance: BasePrototypeCache[K],\n accessor: T,\n): BasePrototypeCache[K][T] {\n const cacheKey = `${key}.${String(accessor)}`;\n if (untaintedAccessorCache[cacheKey])\n return untaintedAccessorCache[cacheKey].call(\n instance,\n ) as BasePrototypeCache[K][T];\n\n const untaintedPrototype = getUntaintedPrototype(key);\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const untaintedAccessor = Object.getOwnPropertyDescriptor(\n untaintedPrototype,\n accessor,\n )?.get;\n\n if (!untaintedAccessor) return instance[accessor];\n\n untaintedAccessorCache[cacheKey] = untaintedAccessor;\n\n return untaintedAccessor.call(instance) as BasePrototypeCache[K][T];\n}\n\ntype BaseMethod<K extends keyof BasePrototypeCache> = (\n this: BasePrototypeCache[K],\n ...args: unknown[]\n) => unknown;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst untaintedMethodCache: Record<string, BaseMethod<any>> = {};\nexport function getUntaintedMethod<\n K extends keyof BasePrototypeCache,\n T extends keyof BasePrototypeCache[K],\n>(\n key: K,\n instance: BasePrototypeCache[K],\n method: T,\n): BasePrototypeCache[K][T] {\n const cacheKey = `${key}.${String(method)}`;\n if (untaintedMethodCache[cacheKey])\n return untaintedMethodCache[cacheKey].bind(\n instance,\n ) as BasePrototypeCache[K][T];\n\n const untaintedPrototype = getUntaintedPrototype(key);\n const untaintedMethod = untaintedPrototype[method];\n\n if (typeof untaintedMethod !== 'function') return instance[method];\n\n untaintedMethodCache[cacheKey] = untaintedMethod as BaseMethod<K>;\n\n return untaintedMethod.bind(instance) as BasePrototypeCache[K][T];\n}\n\nexport function childNodes(n: Node): NodeListOf<Node> {\n return getUntaintedAccessor('Node', n, 'childNodes');\n}\n\nexport function parentNode(n: Node): ParentNode | null {\n return getUntaintedAccessor('Node', n, 'parentNode');\n}\n\nexport function parentElement(n: Node): HTMLElement | null {\n return getUntaintedAccessor('Node', n, 'parentElement');\n}\n\nexport function textContent(n: Node): string | null {\n return getUntaintedAccessor('Node', n, 'textContent');\n}\n\nexport function contains(n: Node, other: Node): boolean {\n return getUntaintedMethod('Node', n, 'contains')(other);\n}\n\nexport function getRootNode(n: Node): Node {\n return getUntaintedMethod('Node', n, 'getRootNode')();\n}\n\nexport function host(n: ShadowRoot): Element | null {\n if (!n || !('host' in n)) return null;\n return getUntaintedAccessor('ShadowRoot', n, 'host');\n}\n\nexport function styleSheets(n: ShadowRoot): StyleSheetList {\n return n.styleSheets;\n}\n\nexport function shadowRoot(n: Node): ShadowRoot | null {\n if (!n || !('shadowRoot' in n)) return null;\n return getUntaintedAccessor('Element', n as Element, 'shadowRoot');\n}\n\nexport function querySelector(n: Element, selectors: string): Element | null {\n return getUntaintedAccessor('Element', n, 'querySelector')(selectors);\n}\n\nexport function querySelectorAll(\n n: Element,\n selectors: string,\n): NodeListOf<Element> {\n return getUntaintedAccessor('Element', n, 'querySelectorAll')(selectors);\n}\n\nexport function mutationObserverCtor(): (typeof MutationObserver)['prototype']['constructor'] {\n return getUntaintedPrototype('MutationObserver').constructor;\n}\n\n// copy from https://github.com/getsentry/sentry-javascript/blob/b2109071975af8bf0316d3b5b38f519bdaf5dc15/packages/utils/src/object.ts\nexport function patch(\n source: { [key: string]: any },\n name: string,\n replacement: (...args: unknown[]) => unknown,\n): () => void {\n try {\n if (!(name in source)) {\n return () => {\n //\n };\n }\n\n const original = source[name] as () => unknown;\n const wrapped = replacement(original);\n\n // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work\n // otherwise it'll throw \"TypeError: Object.defineProperties called on non-object\"\n if (typeof wrapped === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n wrapped.prototype = wrapped.prototype || {};\n Object.defineProperties(wrapped, {\n __rrweb_original__: {\n enumerable: false,\n value: original,\n },\n });\n }\n\n source[name] = wrapped;\n\n return () => {\n source[name] = original;\n };\n } catch {\n return () => {\n //\n };\n // This can throw if multiple fill happens on a global object like XMLHttpRequest\n // Fixes https://github.com/getsentry/sentry-javascript/issues/2043\n }\n}\n\nexport default {\n childNodes,\n parentNode,\n parentElement,\n textContent,\n contains,\n getRootNode,\n host,\n styleSheets,\n shadowRoot,\n querySelector,\n querySelectorAll,\n mutationObserver: mutationObserverCtor,\n patch,\n};\n"],"names":[],"mappings":"AAcA,MAAM,oB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I,IAAI;AAEf,WAAO,MAAM;AACX,aAAO,IAAI,IAAI;AAAA,IAAA;AAAA,EACjB,QACM;AACN,WAAO,MAAM;AAAA,IAAA;AAAA,EAKf;AACF;AAEA,MAAe,QAAA;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,kBAAkB;AAAA,EAClB;AACF;"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
(function (g, f) {
|
|
2
|
+
if ("object" == typeof exports && "object" == typeof module) {
|
|
3
|
+
module.exports = f();
|
|
4
|
+
} else if ("function" == typeof define && define.amd) {
|
|
5
|
+
define("rrwebUtils", [], f);
|
|
6
|
+
} else if ("object" == typeof exports) {
|
|
7
|
+
exports["rrwebUtils"] = f();
|
|
8
|
+
} else {
|
|
9
|
+
g["rrwebUtils"] = f();
|
|
10
|
+
}
|
|
11
|
+
}(this, () => {
|
|
12
|
+
var exports = {};
|
|
13
|
+
var module = { exports };
|
|
14
|
+
"use strict";
|
|
15
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
16
|
+
const testableAccessors = {
|
|
17
|
+
Node: ["childNodes", "parentNode", "parentElement", "textContent"],
|
|
18
|
+
ShadowRoot: ["host", "styleSheets"],
|
|
19
|
+
Element: ["shadowRoot", "querySelector", "querySelectorAll"],
|
|
20
|
+
MutationObserver: []
|
|
21
|
+
};
|
|
22
|
+
const testableMethods = {
|
|
23
|
+
Node: ["contains", "getRootNode"],
|
|
24
|
+
ShadowRoot: ["getSelection"],
|
|
25
|
+
Element: [],
|
|
26
|
+
MutationObserver: ["constructor"]
|
|
27
|
+
};
|
|
28
|
+
const untaintedBasePrototype = {};
|
|
29
|
+
const isAngularZonePresent = () => {
|
|
30
|
+
return !!globalThis.Zone;
|
|
31
|
+
};
|
|
32
|
+
function getUntaintedPrototype(key) {
|
|
33
|
+
if (untaintedBasePrototype[key])
|
|
34
|
+
return untaintedBasePrototype[key];
|
|
35
|
+
const defaultObj = globalThis[key];
|
|
36
|
+
const defaultPrototype = defaultObj.prototype;
|
|
37
|
+
const accessorNames = key in testableAccessors ? testableAccessors[key] : void 0;
|
|
38
|
+
const isUntaintedAccessors = Boolean(
|
|
39
|
+
accessorNames && // @ts-expect-error 2345
|
|
40
|
+
accessorNames.every(
|
|
41
|
+
(accessor) => {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
return Boolean(
|
|
44
|
+
(_b = (_a = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) == null ? void 0 : _a.get) == null ? void 0 : _b.toString().includes("[native code]")
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
const methodNames = key in testableMethods ? testableMethods[key] : void 0;
|
|
50
|
+
const isUntaintedMethods = Boolean(
|
|
51
|
+
methodNames && methodNames.every(
|
|
52
|
+
// @ts-expect-error 2345
|
|
53
|
+
(method) => {
|
|
54
|
+
var _a;
|
|
55
|
+
return typeof defaultPrototype[method] === "function" && ((_a = defaultPrototype[method]) == null ? void 0 : _a.toString().includes("[native code]"));
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
);
|
|
59
|
+
if (isUntaintedAccessors && isUntaintedMethods && !isAngularZonePresent()) {
|
|
60
|
+
untaintedBasePrototype[key] = defaultObj.prototype;
|
|
61
|
+
return defaultObj.prototype;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const iframeEl = document.createElement("iframe");
|
|
65
|
+
document.body.appendChild(iframeEl);
|
|
66
|
+
const win = iframeEl.contentWindow;
|
|
67
|
+
if (!win) return defaultObj.prototype;
|
|
68
|
+
const untaintedObject = win[key].prototype;
|
|
69
|
+
document.body.removeChild(iframeEl);
|
|
70
|
+
if (!untaintedObject) return defaultPrototype;
|
|
71
|
+
return untaintedBasePrototype[key] = untaintedObject;
|
|
72
|
+
} catch (e) {
|
|
73
|
+
return defaultPrototype;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const untaintedAccessorCache = {};
|
|
77
|
+
function getUntaintedAccessor(key, instance, accessor) {
|
|
78
|
+
var _a;
|
|
79
|
+
const cacheKey = `${key}.${String(accessor)}`;
|
|
80
|
+
if (untaintedAccessorCache[cacheKey])
|
|
81
|
+
return untaintedAccessorCache[cacheKey].call(
|
|
82
|
+
instance
|
|
83
|
+
);
|
|
84
|
+
const untaintedPrototype = getUntaintedPrototype(key);
|
|
85
|
+
const untaintedAccessor = (_a = Object.getOwnPropertyDescriptor(
|
|
86
|
+
untaintedPrototype,
|
|
87
|
+
accessor
|
|
88
|
+
)) == null ? void 0 : _a.get;
|
|
89
|
+
if (!untaintedAccessor) return instance[accessor];
|
|
90
|
+
untaintedAccessorCache[cacheKey] = untaintedAccessor;
|
|
91
|
+
return untaintedAccessor.call(instance);
|
|
92
|
+
}
|
|
93
|
+
const untaintedMethodCache = {};
|
|
94
|
+
function getUntaintedMethod(key, instance, method) {
|
|
95
|
+
const cacheKey = `${key}.${String(method)}`;
|
|
96
|
+
if (untaintedMethodCache[cacheKey])
|
|
97
|
+
return untaintedMethodCache[cacheKey].bind(
|
|
98
|
+
instance
|
|
99
|
+
);
|
|
100
|
+
const untaintedPrototype = getUntaintedPrototype(key);
|
|
101
|
+
const untaintedMethod = untaintedPrototype[method];
|
|
102
|
+
if (typeof untaintedMethod !== "function") return instance[method];
|
|
103
|
+
untaintedMethodCache[cacheKey] = untaintedMethod;
|
|
104
|
+
return untaintedMethod.bind(instance);
|
|
105
|
+
}
|
|
106
|
+
function childNodes(n) {
|
|
107
|
+
return getUntaintedAccessor("Node", n, "childNodes");
|
|
108
|
+
}
|
|
109
|
+
function parentNode(n) {
|
|
110
|
+
return getUntaintedAccessor("Node", n, "parentNode");
|
|
111
|
+
}
|
|
112
|
+
function parentElement(n) {
|
|
113
|
+
return getUntaintedAccessor("Node", n, "parentElement");
|
|
114
|
+
}
|
|
115
|
+
function textContent(n) {
|
|
116
|
+
return getUntaintedAccessor("Node", n, "textContent");
|
|
117
|
+
}
|
|
118
|
+
function contains(n, other) {
|
|
119
|
+
return getUntaintedMethod("Node", n, "contains")(other);
|
|
120
|
+
}
|
|
121
|
+
function getRootNode(n) {
|
|
122
|
+
return getUntaintedMethod("Node", n, "getRootNode")();
|
|
123
|
+
}
|
|
124
|
+
function host(n) {
|
|
125
|
+
if (!n || !("host" in n)) return null;
|
|
126
|
+
return getUntaintedAccessor("ShadowRoot", n, "host");
|
|
127
|
+
}
|
|
128
|
+
function styleSheets(n) {
|
|
129
|
+
return n.styleSheets;
|
|
130
|
+
}
|
|
131
|
+
function shadowRoot(n) {
|
|
132
|
+
if (!n || !("shadowRoot" in n)) return null;
|
|
133
|
+
return getUntaintedAccessor("Element", n, "shadowRoot");
|
|
134
|
+
}
|
|
135
|
+
function querySelector(n, selectors) {
|
|
136
|
+
return getUntaintedAccessor("Element", n, "querySelector")(selectors);
|
|
137
|
+
}
|
|
138
|
+
function querySelectorAll(n, selectors) {
|
|
139
|
+
return getUntaintedAccessor("Element", n, "querySelectorAll")(selectors);
|
|
140
|
+
}
|
|
141
|
+
function mutationObserverCtor() {
|
|
142
|
+
return getUntaintedPrototype("MutationObserver").constructor;
|
|
143
|
+
}
|
|
144
|
+
function patch(source, name, replacement) {
|
|
145
|
+
try {
|
|
146
|
+
if (!(name in source)) {
|
|
147
|
+
return () => {
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const original = source[name];
|
|
151
|
+
const wrapped = replacement(original);
|
|
152
|
+
if (typeof wrapped === "function") {
|
|
153
|
+
wrapped.prototype = wrapped.prototype || {};
|
|
154
|
+
Object.defineProperties(wrapped, {
|
|
155
|
+
__rrweb_original__: {
|
|
156
|
+
enumerable: false,
|
|
157
|
+
value: original
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
source[name] = wrapped;
|
|
162
|
+
return () => {
|
|
163
|
+
source[name] = original;
|
|
164
|
+
};
|
|
165
|
+
} catch (e) {
|
|
166
|
+
return () => {
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const index = {
|
|
171
|
+
childNodes,
|
|
172
|
+
parentNode,
|
|
173
|
+
parentElement,
|
|
174
|
+
textContent,
|
|
175
|
+
contains,
|
|
176
|
+
getRootNode,
|
|
177
|
+
host,
|
|
178
|
+
styleSheets,
|
|
179
|
+
shadowRoot,
|
|
180
|
+
querySelector,
|
|
181
|
+
querySelectorAll,
|
|
182
|
+
mutationObserver: mutationObserverCtor,
|
|
183
|
+
patch
|
|
184
|
+
};
|
|
185
|
+
exports.childNodes = childNodes;
|
|
186
|
+
exports.contains = contains;
|
|
187
|
+
exports.default = index;
|
|
188
|
+
exports.getRootNode = getRootNode;
|
|
189
|
+
exports.getUntaintedAccessor = getUntaintedAccessor;
|
|
190
|
+
exports.getUntaintedMethod = getUntaintedMethod;
|
|
191
|
+
exports.getUntaintedPrototype = getUntaintedPrototype;
|
|
192
|
+
exports.host = host;
|
|
193
|
+
exports.isAngularZonePresent = isAngularZonePresent;
|
|
194
|
+
exports.mutationObserverCtor = mutationObserverCtor;
|
|
195
|
+
exports.parentElement = parentElement;
|
|
196
|
+
exports.parentNode = parentNode;
|
|
197
|
+
exports.patch = patch;
|
|
198
|
+
exports.querySelector = querySelector;
|
|
199
|
+
exports.querySelectorAll = querySelectorAll;
|
|
200
|
+
exports.shadowRoot = shadowRoot;
|
|
201
|
+
exports.styleSheets = styleSheets;
|
|
202
|
+
exports.textContent = textContent;
|
|
203
|
+
if (typeof module.exports == "object" && typeof exports == "object") {
|
|
204
|
+
var __cp = (to, from, except, desc) => {
|
|
205
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
206
|
+
for (let key of Object.getOwnPropertyNames(from)) {
|
|
207
|
+
if (!Object.prototype.hasOwnProperty.call(to, key) && key !== except)
|
|
208
|
+
Object.defineProperty(to, key, {
|
|
209
|
+
get: () => from[key],
|
|
210
|
+
enumerable: !(desc = Object.getOwnPropertyDescriptor(from, key)) || desc.enumerable,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return to;
|
|
215
|
+
};
|
|
216
|
+
module.exports = __cp(module.exports, exports);
|
|
217
|
+
}
|
|
218
|
+
return module.exports;
|
|
219
|
+
}))
|
|
220
|
+
//# sourceMappingURL=utils.umd.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["type PrototypeOwner = Node | ShadowRoot | MutationObserver | Element;\ntype TypeofPrototypeOwner =\n | typeof Node\n | typeof ShadowRoot\n | typeof MutationObserver\n | typeof Element;\n\ntype BasePrototypeCache = {\n Node: typeof Node.prototype;\n ShadowRoot: typeof ShadowRoot.prototype;\n MutationObserver: typeof MutationObserver.prototype;\n Element: typeof Element.prototype;\n};\n\nconst testableAccessors = {\n Node: ['childNodes', 'parentNode', 'parentElement', 'textContent'] as const,\n ShadowRoot: ['host', 'styleSheets'] as const,\n Element: ['shadowRoot', 'querySelector', 'querySelectorAll'] as const,\n MutationObserver: [] as const,\n} as const;\n\nconst testableMethods = {\n Node: ['contains', 'getRootNode'] as const,\n ShadowRoot: ['getSelection'],\n Element: [],\n MutationObserver: ['constructor'],\n} as const;\n\nconst untaintedBasePrototype: Partial<BasePrototypeCache> = {};\n\n/*\n When angular patches things - particularly the MutationObserver -\n they pass the `isNativeFunction` check\n That then causes performance issues\n because Angular's change detection\n doesn't like sharing a mutation observer\n Checking for the presence of the Zone object\n on global is a good-enough proxy for Angular\n to cover most cases\n (you can configure zone.js to have a different name\n on the global object and should then manually run rrweb\n outside the Zone)\n */\nexport const isAngularZonePresent = (): boolean => {\n return !!(globalThis as { Zone?: unknown }).Zone;\n};\n\nexport function getUntaintedPrototype<T extends keyof BasePrototypeCache>(\n key: T,\n): BasePrototypeCache[T] {\n if (untaintedBasePrototype[key])\n return untaintedBasePrototype[key] as BasePrototypeCache[T];\n\n const defaultObj = globalThis[key] as TypeofPrototypeOwner;\n const defaultPrototype = defaultObj.prototype as BasePrototypeCache[T];\n\n // use list of testable accessors to check if the prototype is tainted\n const accessorNames =\n key in testableAccessors ? testableAccessors[key] : undefined;\n const isUntaintedAccessors = Boolean(\n accessorNames &&\n // @ts-expect-error 2345\n accessorNames.every((accessor: keyof typeof defaultPrototype) =>\n Boolean(\n Object.getOwnPropertyDescriptor(defaultPrototype, accessor)\n ?.get?.toString()\n .includes('[native code]'),\n ),\n ),\n );\n\n const methodNames = key in testableMethods ? testableMethods[key] : undefined;\n const isUntaintedMethods = Boolean(\n methodNames &&\n methodNames.every(\n // @ts-expect-error 2345\n (method: keyof typeof defaultPrototype) =>\n typeof defaultPrototype[method] === 'function' &&\n defaultPrototype[method]?.toString().includes('[native code]'),\n ),\n );\n\n if (isUntaintedAccessors && isUntaintedMethods && !isAngularZonePresent()) {\n untaintedBasePrototype[key] = defaultObj.prototype as BasePrototypeCache[T];\n return defaultObj.prototype as BasePrototypeCache[T];\n }\n\n try {\n const iframeEl = document.createElement('iframe');\n document.body.appendChild(iframeEl);\n const win = iframeEl.contentWindow;\n if (!win) return defaultObj.prototype as BasePrototypeCache[T];\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n const untaintedObject = (win as any)[key]\n .prototype as BasePrototypeCache[T];\n // cleanup\n document.body.removeChild(iframeEl);\n\n if (!untaintedObject) return defaultPrototype;\n\n return (untaintedBasePrototype[key] = untaintedObject);\n } catch {\n return defaultPrototype;\n }\n}\n\nconst untaintedAccessorCache: Record<\n string,\n (this: PrototypeOwner, ...args: unknown[]) => unknown\n> = {};\n\nexport function getUntaintedAccessor<\n K extends keyof BasePrototypeCache,\n T extends keyof BasePrototypeCache[K],\n>(\n key: K,\n instance: BasePrototypeCache[K],\n accessor: T,\n): BasePrototypeCache[K][T] {\n const cacheKey = `${key}.${String(accessor)}`;\n if (untaintedAccessorCache[cacheKey])\n return untaintedAccessorCache[cacheKey].call(\n instance,\n ) as BasePrototypeCache[K][T];\n\n const untaintedPrototype = getUntaintedPrototype(key);\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const untaintedAccessor = Object.getOwnPropertyDescriptor(\n untaintedPrototype,\n accessor,\n )?.get;\n\n if (!untaintedAccessor) return instance[accessor];\n\n untaintedAccessorCache[cacheKey] = untaintedAccessor;\n\n return untaintedAccessor.call(instance) as BasePrototypeCache[K][T];\n}\n\ntype BaseMethod<K extends keyof BasePrototypeCache> = (\n this: BasePrototypeCache[K],\n ...args: unknown[]\n) => unknown;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst untaintedMethodCache: Record<string, BaseMethod<any>> = {};\nexport function getUntaintedMethod<\n K extends keyof BasePrototypeCache,\n T extends keyof BasePrototypeCache[K],\n>(\n key: K,\n instance: BasePrototypeCache[K],\n method: T,\n): BasePrototypeCache[K][T] {\n const cacheKey = `${key}.${String(method)}`;\n if (untaintedMethodCache[cacheKey])\n return untaintedMethodCache[cacheKey].bind(\n instance,\n ) as BasePrototypeCache[K][T];\n\n const untaintedPrototype = getUntaintedPrototype(key);\n const untaintedMethod = untaintedPrototype[method];\n\n if (typeof untaintedMethod !== 'function') return instance[method];\n\n untaintedMethodCache[cacheKey] = untaintedMethod as BaseMethod<K>;\n\n return untaintedMethod.bind(instance) as BasePrototypeCache[K][T];\n}\n\nexport function childNodes(n: Node): NodeListOf<Node> {\n return getUntaintedAccessor('Node', n, 'childNodes');\n}\n\nexport function parentNode(n: Node): ParentNode | null {\n return getUntaintedAccessor('Node', n, 'parentNode');\n}\n\nexport function parentElement(n: Node): HTMLElement | null {\n return getUntaintedAccessor('Node', n, 'parentElement');\n}\n\nexport function textContent(n: Node): string | null {\n return getUntaintedAccessor('Node', n, 'textContent');\n}\n\nexport function contains(n: Node, other: Node): boolean {\n return getUntaintedMethod('Node', n, 'contains')(other);\n}\n\nexport function getRootNode(n: Node): Node {\n return getUntaintedMethod('Node', n, 'getRootNode')();\n}\n\nexport function host(n: ShadowRoot): Element | null {\n if (!n || !('host' in n)) return null;\n return getUntaintedAccessor('ShadowRoot', n, 'host');\n}\n\nexport function styleSheets(n: ShadowRoot): StyleSheetList {\n return n.styleSheets;\n}\n\nexport function shadowRoot(n: Node): ShadowRoot | null {\n if (!n || !('shadowRoot' in n)) return null;\n return getUntaintedAccessor('Element', n as Element, 'shadowRoot');\n}\n\nexport function querySelector(n: Element, selectors: string): Element | null {\n return getUntaintedAccessor('Element', n, 'querySelector')(selectors);\n}\n\nexport function querySelectorAll(\n n: Element,\n selectors: string,\n): NodeListOf<Element> {\n return getUntaintedAccessor('Element', n, 'querySelectorAll')(selectors);\n}\n\nexport function mutationObserverCtor(): (typeof MutationObserver)['prototype']['constructor'] {\n return getUntaintedPrototype('MutationObserver').constructor;\n}\n\n// copy from https://github.com/getsentry/sentry-javascript/blob/b2109071975af8bf0316d3b5b38f519bdaf5dc15/packages/utils/src/object.ts\nexport function patch(\n source: { [key: string]: any },\n name: string,\n replacement: (...args: unknown[]) => unknown,\n): () => void {\n try {\n if (!(name in source)) {\n return () => {\n //\n };\n }\n\n const original = source[name] as () => unknown;\n const wrapped = replacement(original);\n\n // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work\n // otherwise it'll throw \"TypeError: Object.defineProperties called on non-object\"\n if (typeof wrapped === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n wrapped.prototype = wrapped.prototype || {};\n Object.defineProperties(wrapped, {\n __rrweb_original__: {\n enumerable: false,\n value: original,\n },\n });\n }\n\n source[name] = wrapped;\n\n return () => {\n source[name] = original;\n };\n } catch {\n return () => {\n //\n };\n // This can throw if multiple fill happens on a global object like XMLHttpRequest\n // Fixes https://github.com/getsentry/sentry-javascript/issues/2043\n }\n}\n\nexport default {\n childNodes,\n parentNode,\n parentElement,\n textContent,\n contains,\n getRootNode,\n host,\n styleSheets,\n shadowRoot,\n querySelector,\n querySelectorAll,\n mutationObserver: mutationObserverCtor,\n patch,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAcA,MAAM,oBAAoB;EACxB,MAAM,CAAC,cAAc,cAAc,iBAAiB,aAAa;EACjE,YAAY,CAAC,QAAQ,aAAa;EAClC,SAAS,CAAC,cAAc,iBAAiB,kBAAkB;EAC3D,kBAAkB,CAAC;AACrB;AAEA,MAAM,kBAAkB;EACtB,MAAM,CAAC,YAAY,aAAa;EAChC,YAAY,CAAC,cAAc;EAC3B,SAAS,CAAC;EACV,kBAAkB,CAAC,aAAa;AAClC;AAEA,MAAM,yBAAsD,CAAA;AAerD,MAAM,uBAAuB,MAAe;AAC1C,SAAA,CAAC,CAAE,WAAkC;AAC9C;AAEO,SAAS,sBACd,KACuB;AACvB,MAAI,uBAAuB,GAAG;AAC5B,WAAO,uBAAuB,GAAG;AAE7B,QAAA,aAAa,WAAW,GAAG;AACjC,QAAM,mBAAmB,WAAW;AAGpC,QAAM,gBACJ,OAAO,oBAAoB,kBAAkB,GAAG,IAAI;AACtD,QAAM,uBAAuB;IAC3B;IAEE,cAAc;MAAM,CAAC,aACnB;;AAAA,eAAA;WACE,MAAA,KAAA,OAAO,yBAAyB,kBAAkB,QAAQ,MAA1D,OAAA,SAAA,GACI,QADJ,OAAA,SAAA,GACS,SAAA,EACN,SAAS,eAAA;QACd;MAAA;IACF;EAAA;AAGJ,QAAM,cAAc,OAAO,kBAAkB,gBAAgB,GAAG,IAAI;AACpE,QAAM,qBAAqB;IACzB,eACE,YAAY;;MAEV,CAAC,WACC;;AAAA,eAAA,OAAO,iBAAiB,MAAM,MAAM,gBACpC,KAAA,iBAAiB,MAAM,MAAvB,OAAA,SAAA,GAA0B,SAAA,EAAW,SAAS,eAAA;MAAA;IAClD;EAAA;AAGJ,MAAI,wBAAwB,sBAAsB,CAAC,qBAAA,GAAwB;AAClD,2BAAA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A,WAAO,IAAI,IAAI;AAEf,WAAO,MAAM;AACX,aAAO,IAAI,IAAI;IAAA;EACjB,SACM;AACN,WAAO,MAAM;IAAA;EAKf;AACF;AAEA,MAAe,QAAA;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,kBAAkB;EAClB;AACF;;;;;;;;;;;;;;;;;;;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
(function (g, f) {
|
|
2
|
+
if ("object" == typeof exports && "object" == typeof module) {
|
|
3
|
+
module.exports = f();
|
|
4
|
+
} else if ("function" == typeof define && define.amd) {
|
|
5
|
+
define("rrwebUtils", [], f);
|
|
6
|
+
} else if ("object" == typeof exports) {
|
|
7
|
+
exports["rrwebUtils"] = f();
|
|
8
|
+
} else {
|
|
9
|
+
g["rrwebUtils"] = f();
|
|
10
|
+
}
|
|
11
|
+
}(this, () => {
|
|
12
|
+
var exports = {};
|
|
13
|
+
var module = { exports };
|
|
14
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g={Node:["childNodes","parentNode","parentElement","textContent"],ShadowRoot:["host","styleSheets"],Element:["shadowRoot","querySelector","querySelectorAll"],MutationObserver:[]},b={Node:["contains","getRootNode"],ShadowRoot:["getSelection"],Element:[],MutationObserver:["constructor"]},l={},v=()=>!!globalThis.Zone;function p(t){if(l[t])return l[t];const e=globalThis[t],o=e.prototype,n=t in g?g[t]:void 0,r=!!(n&&n.every(i=>{var s,a;return!!((a=(s=Object.getOwnPropertyDescriptor(o,i))==null?void 0:s.get)!=null&&a.toString().includes("[native code]"))})),u=t in b?b[t]:void 0,d=!!(u&&u.every(i=>{var s;return typeof o[i]=="function"&&((s=o[i])==null?void 0:s.toString().includes("[native code]"))}));if(r&&d&&!v())return l[t]=e.prototype,e.prototype;try{const i=document.createElement("iframe");document.body.appendChild(i);const s=i.contentWindow;if(!s)return e.prototype;const a=s[t].prototype;return document.body.removeChild(i),a?l[t]=a:o}catch(i){return o}}const f={};function c(t,e,o){var n;const r=`${t}.${String(o)}`;if(f[r])return f[r].call(e);const u=p(t),d=(n=Object.getOwnPropertyDescriptor(u,o))==null?void 0:n.get;return d?(f[r]=d,d.call(e)):e[o]}const h={};function y(t,e,o){const n=`${t}.${String(o)}`;if(h[n])return h[n].bind(e);const u=p(t)[o];return typeof u!="function"?e[o]:(h[n]=u,u.bind(e))}function N(t){return c("Node",t,"childNodes")}function S(t){return c("Node",t,"parentNode")}function m(t){return c("Node",t,"parentElement")}function w(t){return c("Node",t,"textContent")}function O(t,e){return y("Node",t,"contains")(e)}function P(t){return y("Node",t,"getRootNode")()}function A(t){return!t||!("host"in t)?null:c("ShadowRoot",t,"host")}function R(t){return t.styleSheets}function E(t){return!t||!("shadowRoot"in t)?null:c("Element",t,"shadowRoot")}function M(t,e){return c("Element",t,"querySelector")(e)}function _(t,e){return c("Element",t,"querySelectorAll")(e)}function C(){return p("MutationObserver").constructor}function q(t,e,o){try{if(!(e in t))return()=>{};const n=t[e],r=o(n);return typeof r=="function"&&(r.prototype=r.prototype||{},Object.defineProperties(r,{__rrweb_original__:{enumerable:!1,value:n}})),t[e]=r,()=>{t[e]=n}}catch(n){return()=>{}}}const U={childNodes:N,parentNode:S,parentElement:m,textContent:w,contains:O,getRootNode:P,host:A,styleSheets:R,shadowRoot:E,querySelector:M,querySelectorAll:_,mutationObserver:C,patch:q};exports.childNodes=N;exports.contains=O;exports.default=U;exports.getRootNode=P;exports.getUntaintedAccessor=c;exports.getUntaintedMethod=y;exports.getUntaintedPrototype=p;exports.host=A;exports.isAngularZonePresent=v;exports.mutationObserverCtor=C;exports.parentElement=m;exports.parentNode=S;exports.patch=q;exports.querySelector=M;exports.querySelectorAll=_;exports.shadowRoot=E;exports.styleSheets=R;exports.textContent=w;
|
|
15
|
+
if (typeof module.exports == "object" && typeof exports == "object") {
|
|
16
|
+
var __cp = (to, from, except, desc) => {
|
|
17
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
18
|
+
for (let key of Object.getOwnPropertyNames(from)) {
|
|
19
|
+
if (!Object.prototype.hasOwnProperty.call(to, key) && key !== except)
|
|
20
|
+
Object.defineProperty(to, key, {
|
|
21
|
+
get: () => from[key],
|
|
22
|
+
enumerable: !(desc = Object.getOwnPropertyDescriptor(from, key)) || desc.enumerable,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
module.exports = __cp(module.exports, exports);
|
|
29
|
+
}
|
|
30
|
+
return module.exports;
|
|
31
|
+
}))
|
|
32
|
+
//# sourceMappingURL=utils.umd.min.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["type PrototypeOwner = Node | ShadowRoot | MutationObserver | Element;\ntype TypeofPrototypeOwner =\n | typeof Node\n | typeof ShadowRoot\n | typeof MutationObserver\n | typeof Element;\n\ntype BasePrototypeCache = {\n Node: typeof Node.prototype;\n ShadowRoot: typeof ShadowRoot.prototype;\n MutationObserver: typeof MutationObserver.prototype;\n Element: typeof Element.prototype;\n};\n\nconst testableAccessors = {\n Node: ['childNodes', 'parentNode', 'parentElement', 'textContent'] as const,\n ShadowRoot: ['host', 'styleSheets'] as const,\n Element: ['shadowRoot', 'querySelector', 'querySelectorAll'] as const,\n MutationObserver: [] as const,\n} as const;\n\nconst testableMethods = {\n Node: ['contains', 'getRootNode'] as const,\n ShadowRoot: ['getSelection'],\n Element: [],\n MutationObserver: ['constructor'],\n} as const;\n\nconst untaintedBasePrototype: Partial<BasePrototypeCache> = {};\n\n/*\n When angular patches things - particularly the MutationObserver -\n they pass the `isNativeFunction` check\n That then causes performance issues\n because Angular's change detection\n doesn't like sharing a mutation observer\n Checking for the presence of the Zone object\n on global is a good-enough proxy for Angular\n to cover most cases\n (you can configure zone.js to have a different name\n on the global object and should then manually run rrweb\n outside the Zone)\n */\nexport const isAngularZonePresent = (): boolean => {\n return !!(globalThis as { Zone?: unknown }).Zone;\n};\n\nexport function getUntaintedPrototype<T extends keyof BasePrototypeCache>(\n key: T,\n): BasePrototypeCache[T] {\n if (untaintedBasePrototype[key])\n return untaintedBasePrototype[key] as BasePrototypeCache[T];\n\n const defaultObj = globalThis[key] as TypeofPrototypeOwner;\n const defaultPrototype = defaultObj.prototype as BasePrototypeCache[T];\n\n // use list of testable accessors to check if the prototype is tainted\n const accessorNames =\n key in testableAccessors ? testableAccessors[key] : undefined;\n const isUntaintedAccessors = Boolean(\n accessorNames &&\n // @ts-expect-error 2345\n accessorNames.every((accessor: keyof typeof defaultPrototype) =>\n Boolean(\n Object.getOwnPropertyDescriptor(defaultPrototype, accessor)\n ?.get?.toString()\n .includes('[native code]'),\n ),\n ),\n );\n\n const methodNames = key in testableMethods ? testableMethods[key] : undefined;\n const isUntaintedMethods = Boolean(\n methodNames &&\n methodNames.every(\n // @ts-expect-error 2345\n (method: keyof typeof defaultPrototype) =>\n typeof defaultPrototype[method] === 'function' &&\n defaultPrototype[method]?.toString().includes('[native code]'),\n ),\n );\n\n if (isUntaintedAccessors && isUntaintedMethods && !isAngularZonePresent()) {\n untaintedBasePrototype[key] = defaultObj.prototype as BasePrototypeCache[T];\n return defaultObj.prototype as BasePrototypeCache[T];\n }\n\n try {\n const iframeEl = document.createElement('iframe');\n document.body.appendChild(iframeEl);\n const win = iframeEl.contentWindow;\n if (!win) return defaultObj.prototype as BasePrototypeCache[T];\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n const untaintedObject = (win as any)[key]\n .prototype as BasePrototypeCache[T];\n // cleanup\n document.body.removeChild(iframeEl);\n\n if (!untaintedObject) return defaultPrototype;\n\n return (untaintedBasePrototype[key] = untaintedObject);\n } catch {\n return defaultPrototype;\n }\n}\n\nconst untaintedAccessorCache: Record<\n string,\n (this: PrototypeOwner, ...args: unknown[]) => unknown\n> = {};\n\nexport function getUntaintedAccessor<\n K extends keyof BasePrototypeCache,\n T extends keyof BasePrototypeCache[K],\n>(\n key: K,\n instance: BasePrototypeCache[K],\n accessor: T,\n): BasePrototypeCache[K][T] {\n const cacheKey = `${key}.${String(accessor)}`;\n if (untaintedAccessorCache[cacheKey])\n return untaintedAccessorCache[cacheKey].call(\n instance,\n ) as BasePrototypeCache[K][T];\n\n const untaintedPrototype = getUntaintedPrototype(key);\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const untaintedAccessor = Object.getOwnPropertyDescriptor(\n untaintedPrototype,\n accessor,\n )?.get;\n\n if (!untaintedAccessor) return instance[accessor];\n\n untaintedAccessorCache[cacheKey] = untaintedAccessor;\n\n return untaintedAccessor.call(instance) as BasePrototypeCache[K][T];\n}\n\ntype BaseMethod<K extends keyof BasePrototypeCache> = (\n this: BasePrototypeCache[K],\n ...args: unknown[]\n) => unknown;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst untaintedMethodCache: Record<string, BaseMethod<any>> = {};\nexport function getUntaintedMethod<\n K extends keyof BasePrototypeCache,\n T extends keyof BasePrototypeCache[K],\n>(\n key: K,\n instance: BasePrototypeCache[K],\n method: T,\n): BasePrototypeCache[K][T] {\n const cacheKey = `${key}.${String(method)}`;\n if (untaintedMethodCache[cacheKey])\n return untaintedMethodCache[cacheKey].bind(\n instance,\n ) as BasePrototypeCache[K][T];\n\n const untaintedPrototype = getUntaintedPrototype(key);\n const untaintedMethod = untaintedPrototype[method];\n\n if (typeof untaintedMethod !== 'function') return instance[method];\n\n untaintedMethodCache[cacheKey] = untaintedMethod as BaseMethod<K>;\n\n return untaintedMethod.bind(instance) as BasePrototypeCache[K][T];\n}\n\nexport function childNodes(n: Node): NodeListOf<Node> {\n return getUntaintedAccessor('Node', n, 'childNodes');\n}\n\nexport function parentNode(n: Node): ParentNode | null {\n return getUntaintedAccessor('Node', n, 'parentNode');\n}\n\nexport function parentElement(n: Node): HTMLElement | null {\n return getUntaintedAccessor('Node', n, 'parentElement');\n}\n\nexport function textContent(n: Node): string | null {\n return getUntaintedAccessor('Node', n, 'textContent');\n}\n\nexport function contains(n: Node, other: Node): boolean {\n return getUntaintedMethod('Node', n, 'contains')(other);\n}\n\nexport function getRootNode(n: Node): Node {\n return getUntaintedMethod('Node', n, 'getRootNode')();\n}\n\nexport function host(n: ShadowRoot): Element | null {\n if (!n || !('host' in n)) return null;\n return getUntaintedAccessor('ShadowRoot', n, 'host');\n}\n\nexport function styleSheets(n: ShadowRoot): StyleSheetList {\n return n.styleSheets;\n}\n\nexport function shadowRoot(n: Node): ShadowRoot | null {\n if (!n || !('shadowRoot' in n)) return null;\n return getUntaintedAccessor('Element', n as Element, 'shadowRoot');\n}\n\nexport function querySelector(n: Element, selectors: string): Element | null {\n return getUntaintedAccessor('Element', n, 'querySelector')(selectors);\n}\n\nexport function querySelectorAll(\n n: Element,\n selectors: string,\n): NodeListOf<Element> {\n return getUntaintedAccessor('Element', n, 'querySelectorAll')(selectors);\n}\n\nexport function mutationObserverCtor(): (typeof MutationObserver)['prototype']['constructor'] {\n return getUntaintedPrototype('MutationObserver').constructor;\n}\n\n// copy from https://github.com/getsentry/sentry-javascript/blob/b2109071975af8bf0316d3b5b38f519bdaf5dc15/packages/utils/src/object.ts\nexport function patch(\n source: { [key: string]: any },\n name: string,\n replacement: (...args: unknown[]) => unknown,\n): () => void {\n try {\n if (!(name in source)) {\n return () => {\n //\n };\n }\n\n const original = source[name] as () => unknown;\n const wrapped = replacement(original);\n\n // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work\n // otherwise it'll throw \"TypeError: Object.defineProperties called on non-object\"\n if (typeof wrapped === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n wrapped.prototype = wrapped.prototype || {};\n Object.defineProperties(wrapped, {\n __rrweb_original__: {\n enumerable: false,\n value: original,\n },\n });\n }\n\n source[name] = wrapped;\n\n return () => {\n source[name] = original;\n };\n } catch {\n return () => {\n //\n };\n // This can throw if multiple fill happens on a global object like XMLHttpRequest\n // Fixes https://github.com/getsentry/sentry-javascript/issues/2043\n }\n}\n\nexport default {\n childNodes,\n parentNode,\n parentElement,\n textContent,\n contains,\n getRootNode,\n host,\n styleSheets,\n shadowRoot,\n querySelector,\n querySelectorAll,\n mutationObserver: mutationObserverCtor,\n patch,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;4GAcA,MAAMA,EAAoB,CACxB,KAAM,CAAC,aAAc,aAAc,gBAAiB,aAAa,EACjE,WAAY,CAAC,OAAQ,aAAa,EAClC,QAAS,CAAC,aAAc,gBAAiB,kBAAkB,EAC3D,iBAAkB,CAAC,CACrB,EAEMC,EAAkB,CACtB,KAAM,CAAC,WAAY,aAAa,EAChC,WAAY,CAAC,cAAc,EAC3B,QAAS,CAAC,EACV,iBAAkB,CAAC,aAAa,CAClC,EAEMC,EAAsD,CAAA,EAe/CC,EAAuB,IAC3B,CAAC,CAAE,WAAkC,KAGvC,SAASC,EACdC,EACuB,CACvB,GAAIH,EAAuBG,CAAG,EAC5B,OAAOH,EAAuBG,CAAG,EAE7B,MAAAC,EAAa,WAAWD,CAAG,EAC3BE,EAAmBD,EAAW,UAG9BE,EACJH,KAAOL,EAAoBA,EAAkBK,CAAG,EAAI,OAChDI,EAAuB,GAC3BD,GAEEA,EAAc,MAAOE,GACnB,SAAA,MAAA,IACEC,GAAAC,EAAA,OAAO,yBAAyBL,EAAkBG,CAAQ,IAA1D,KAAA,OAAAE,EACI,MADJ,MAAAD,EACS,SAAA,EACN,SAAS,eAAA,EACd,CACF,GAGEE,EAAcR,KAAOJ,EAAkBA,EAAgBI,CAAG,EAAI,OAC9DS,EAAqB,GACzBD,GACEA,EAAY,MAETE,GACC,OAAA,OAAA,OAAOR,EAAiBQ,CAAM,GAAM,cACpCH,EAAAL,EAAiBQ,CAAM,IAAvB,KAAA,OAAAH,EAA0B,SAA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C,OAAO,iBAAiBA,EAAS,CAC/B,mBAAoB,CAClB,WAAY,GACZ,MAAOD,CACT,CAAA,CACD,GAGHH,EAAOC,CAAI,EAAIG,EAER,IAAM,CACXJ,EAAOC,CAAI,EAAIE,CAAA,CACjB,OACM7B,EAAA,CACN,MAAO,IAAM,CAAA,CAKf,CACF,CAEA,MAAe+B,EAAA,CACb,WAAArB,EACA,WAAAE,EACA,cAAAC,EACA,YAAAC,EACA,SAAAC,EACA,YAAAE,EACA,KAAAC,EACA,YAAAC,EACA,WAAAC,EACA,cAAAC,EACA,iBAAAE,EACA,iBAAkBC,EAClB,MAAAC,CACF",
|
|
6
|
+
"names": ["testableAccessors", "testableMethods", "untaintedBasePrototype", "isAngularZonePresent", "getUntaintedPrototype", "key", "defaultObj", "defaultPrototype", "accessorNames", "isUntaintedAccessors", "accessor", "_b", "_a", "methodNames", "isUntaintedMethods", "method", "iframeEl", "win", "untaintedObject", "e", "untaintedAccessorCache", "getUntaintedAccessor", "instance", "cacheKey", "untaintedPrototype", "untaintedAccessor", "untaintedMethodCache", "getUntaintedMethod", "untaintedMethod", "childNodes", "n", "parentNode", "parentElement", "textContent", "contains", "other", "getRootNode", "host", "styleSheets", "shadowRoot", "querySelector", "selectors", "querySelectorAll", "mutationObserverCtor", "patch", "source", "name", "replacement", "original", "wrapped", "index"]
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@betterbugs/utils",
|
|
3
|
+
"version": "2.0.0-alpha.19",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"keywords": [
|
|
8
|
+
"rrweb",
|
|
9
|
+
"betterbugs",
|
|
10
|
+
"@betterbugs/utils"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"dev": "vite build --watch",
|
|
14
|
+
"build": "tsc -noEmit && vite build",
|
|
15
|
+
"check-types": "tsc -noEmit",
|
|
16
|
+
"prepublish": "npm run build",
|
|
17
|
+
"lint": "yarn eslint src/**/*.ts"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/BetterBugs-Team/rrweb/tree/main/packages/utils#readme",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/BetterBugs-Team/rrweb/issues"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/BetterBugs-Team/rrweb.git"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"type": "module",
|
|
29
|
+
"main": "./dist/utils.umd.cjs",
|
|
30
|
+
"module": "./dist/utils.js",
|
|
31
|
+
"unpkg": "./dist/utils.umd.cjs",
|
|
32
|
+
"typings": "dist/index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"default": "./dist/utils.js"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./dist/index.d.cts",
|
|
41
|
+
"default": "./dist/utils.umd.cjs"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"dist",
|
|
47
|
+
"package.json"
|
|
48
|
+
],
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"vite": "^5.2.8",
|
|
51
|
+
"vite-plugin-dts": "^3.8.1"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {}
|
|
54
|
+
}
|