@betterbugs/utils 2.0.0-alpha.20 → 2.0.0-alpha.21
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/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/utils.cjs +12 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.js +12 -1
- package/dist/utils.js.map +1 -1
- package/dist/utils.umd.cjs +12 -1
- package/dist/utils.umd.cjs.map +2 -2
- package/dist/utils.umd.min.cjs +1 -1
- package/dist/utils.umd.min.cjs.map +3 -3
- package/package.json +3 -2
- package/umd/utils.js +231 -0
- package/umd/utils.min.js +32 -0
package/dist/index.d.cts
CHANGED
|
@@ -10,6 +10,7 @@ export declare function childNodes(n: Node): NodeListOf<Node>;
|
|
|
10
10
|
export declare function contains(n: Node, other: Node): boolean;
|
|
11
11
|
|
|
12
12
|
declare const _default: {
|
|
13
|
+
ownerDocument: typeof ownerDocument;
|
|
13
14
|
childNodes: typeof childNodes;
|
|
14
15
|
parentNode: typeof parentNode;
|
|
15
16
|
parentElement: typeof parentElement;
|
|
@@ -40,6 +41,8 @@ export declare const isAngularZonePresent: () => boolean;
|
|
|
40
41
|
|
|
41
42
|
export declare function mutationObserverCtor(): (typeof MutationObserver)['prototype']['constructor'];
|
|
42
43
|
|
|
44
|
+
export declare function ownerDocument(n: Node): Document | null;
|
|
45
|
+
|
|
43
46
|
export declare function parentElement(n: Node): HTMLElement | null;
|
|
44
47
|
|
|
45
48
|
export declare function parentNode(n: Node): ParentNode | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare function childNodes(n: Node): NodeListOf<Node>;
|
|
|
10
10
|
export declare function contains(n: Node, other: Node): boolean;
|
|
11
11
|
|
|
12
12
|
declare const _default: {
|
|
13
|
+
ownerDocument: typeof ownerDocument;
|
|
13
14
|
childNodes: typeof childNodes;
|
|
14
15
|
parentNode: typeof parentNode;
|
|
15
16
|
parentElement: typeof parentElement;
|
|
@@ -40,6 +41,8 @@ export declare const isAngularZonePresent: () => boolean;
|
|
|
40
41
|
|
|
41
42
|
export declare function mutationObserverCtor(): (typeof MutationObserver)['prototype']['constructor'];
|
|
42
43
|
|
|
44
|
+
export declare function ownerDocument(n: Node): Document | null;
|
|
45
|
+
|
|
43
46
|
export declare function parentElement(n: Node): HTMLElement | null;
|
|
44
47
|
|
|
45
48
|
export declare function parentNode(n: Node): ParentNode | null;
|
package/dist/utils.cjs
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
3
|
const testableAccessors = {
|
|
4
|
-
Node: [
|
|
4
|
+
Node: [
|
|
5
|
+
"childNodes",
|
|
6
|
+
"parentNode",
|
|
7
|
+
"parentElement",
|
|
8
|
+
"textContent",
|
|
9
|
+
"ownerDocument"
|
|
10
|
+
],
|
|
5
11
|
ShadowRoot: ["host", "styleSheets"],
|
|
6
12
|
Element: ["shadowRoot", "querySelector", "querySelectorAll"],
|
|
7
13
|
MutationObserver: []
|
|
@@ -90,6 +96,9 @@ function getUntaintedMethod(key, instance, method) {
|
|
|
90
96
|
untaintedMethodCache[cacheKey] = untaintedMethod;
|
|
91
97
|
return untaintedMethod.bind(instance);
|
|
92
98
|
}
|
|
99
|
+
function ownerDocument(n) {
|
|
100
|
+
return getUntaintedAccessor("Node", n, "ownerDocument");
|
|
101
|
+
}
|
|
93
102
|
function childNodes(n) {
|
|
94
103
|
return getUntaintedAccessor("Node", n, "childNodes");
|
|
95
104
|
}
|
|
@@ -155,6 +164,7 @@ function patch(source, name, replacement) {
|
|
|
155
164
|
}
|
|
156
165
|
}
|
|
157
166
|
const index = {
|
|
167
|
+
ownerDocument,
|
|
158
168
|
childNodes,
|
|
159
169
|
parentNode,
|
|
160
170
|
parentElement,
|
|
@@ -179,6 +189,7 @@ exports.getUntaintedPrototype = getUntaintedPrototype;
|
|
|
179
189
|
exports.host = host;
|
|
180
190
|
exports.isAngularZonePresent = isAngularZonePresent;
|
|
181
191
|
exports.mutationObserverCtor = mutationObserverCtor;
|
|
192
|
+
exports.ownerDocument = ownerDocument;
|
|
182
193
|
exports.parentElement = parentElement;
|
|
183
194
|
exports.parentNode = parentNode;
|
|
184
195
|
exports.patch = patch;
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +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 querySel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,QACT;AAAA,MAAA,CACD;AAAA,IACH;AAEA,WAAO,IAAI,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;;;;;;;;;;;;;;;;;;;"}
|
|
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: [\n 'childNodes',\n 'parentNode',\n 'parentElement',\n 'textContent',\n 'ownerDocument',\n ] 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 ownerDocument(n: Node): Document | null {\n return getUntaintedAccessor('Node', n, 'ownerDocument');\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 ownerDocument,\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;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY,CAAC,QAAQ,aAAa;AAAA,EAClC,SAAS,CAAC,cAAc,iBAAiB,kBAAkB;AAAA,EAC3D,kBAAkB,CAAA;AACpB;AAEA,MAAM,kBAAkB;AAAA,EACtB,MAAM,CAAC,YAAY,aAAa;AAAA,EAChC,YAAY,CAAC,cAAc;AAAA,EAC3B,SAAS,CAAC;AAAA,EACV,kBAAkB,CAAC,aAAa;AAClC;AAEA,MAAM,yBAAsD,CAAC;AAetD,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;AAAA,IAC3B;AAAA,IAEE,cAAc;AAAA,MAAM,CAAC,aACnB;;AAAA;AAAA,WACE,kBAAO,yBAAyB,kBAAkB,QAAQ,MAA1D,mBACI,QADJ,mBACS,WACN,SAAS;AAAA,QAAe;AAAA;AAAA,IAC7B;AAAA,EAEN;AAEA,QAAM,cAAc,OAAO,kBAAkB,gBAAgB,GAAG,IAAI;AACpE,QAAM,qBAAqB;AAAA,IACzB,eACE,YAAY;AAAA;AAAA,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A,MACA,aACY;AACR,MAAA;AACE,QAAA,EAAE,QAAQ,SAAS;AACrB,aAAO,MAAM;AAAA,MAEb;AAAA,IAAA;AAGI,UAAA,WAAW,OAAO,IAAI;AACtB,UAAA,UAAU,YAAY,QAAQ;AAIhC,QAAA,OAAO,YAAY,YAAY;AAEzB,cAAA,YAAY,QAAQ,aAAa,CAAC;AAC1C,aAAO,iBAAiB,SAAS;AAAA,QAC/B,oBAAoB;AAAA,UAClB,YAAY;AAAA,UACZ,OAAO;AAAA,QAAA;AAAA,MACT,CACD;AAAA,IAAA;AAGH,WAAO,IAAI,IAAI;AAEf,WAAO,MAAM;AACX,aAAO,IAAI,IAAI;AAAA,IACjB;AAAA,EAAA,QACM;AACN,WAAO,MAAM;AAAA,IAEb;AAAA,EAAA;AAIJ;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;AAAA,EACA,kBAAkB;AAAA,EAClB;AACF;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
const testableAccessors = {
|
|
2
|
-
Node: [
|
|
2
|
+
Node: [
|
|
3
|
+
"childNodes",
|
|
4
|
+
"parentNode",
|
|
5
|
+
"parentElement",
|
|
6
|
+
"textContent",
|
|
7
|
+
"ownerDocument"
|
|
8
|
+
],
|
|
3
9
|
ShadowRoot: ["host", "styleSheets"],
|
|
4
10
|
Element: ["shadowRoot", "querySelector", "querySelectorAll"],
|
|
5
11
|
MutationObserver: []
|
|
@@ -88,6 +94,9 @@ function getUntaintedMethod(key, instance, method) {
|
|
|
88
94
|
untaintedMethodCache[cacheKey] = untaintedMethod;
|
|
89
95
|
return untaintedMethod.bind(instance);
|
|
90
96
|
}
|
|
97
|
+
function ownerDocument(n) {
|
|
98
|
+
return getUntaintedAccessor("Node", n, "ownerDocument");
|
|
99
|
+
}
|
|
91
100
|
function childNodes(n) {
|
|
92
101
|
return getUntaintedAccessor("Node", n, "childNodes");
|
|
93
102
|
}
|
|
@@ -153,6 +162,7 @@ function patch(source, name, replacement) {
|
|
|
153
162
|
}
|
|
154
163
|
}
|
|
155
164
|
const index = {
|
|
165
|
+
ownerDocument,
|
|
156
166
|
childNodes,
|
|
157
167
|
parentNode,
|
|
158
168
|
parentElement,
|
|
@@ -178,6 +188,7 @@ export {
|
|
|
178
188
|
host,
|
|
179
189
|
isAngularZonePresent,
|
|
180
190
|
mutationObserverCtor,
|
|
191
|
+
ownerDocument,
|
|
181
192
|
parentElement,
|
|
182
193
|
parentNode,
|
|
183
194
|
patch,
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +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,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,CAAC,cAAc;AAAA,EAC3B,SAAS,CAAC;AAAA,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;AAAA,IAC3B;AAAA,IAEE,cAAc;AAAA,MAAM,CAAC,aACnB;AAjDR;AAiDQ;AAAA,WACE,kBAAO,yBAAyB,kBAAkB,QAAQ,MAA1D,mBACI,QADJ,mBACS,WACN,SAAS;AAAA,QACd;AAAA;AAAA,IACF;AAAA,EAAA;AAGJ,QAAM,cAAc,OAAO,kBAAkB,gBAAgB,GAAG,IAAI;AACpE,QAAM,qBAAqB;AAAA,IACzB,eACE,YAAY;AAAA;AAAA,MAEV,CAAC,WAC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AA,MAAA;AAAA,IAGf;AAEM,UAAA,WAAW,OAAO,IAAI;AACtB,UAAA,UAAU,YAAY,QAAQ;AAIhC,QAAA,OAAO,YAAY,YAAY;AAEzB,cAAA,YAAY,QAAQ,aAAa,CAAA;AACzC,aAAO,iBAAiB,SAAS;AAAA,QAC/B,oBAAoB;AAAA,UAClB,YAAY;AAAA,UACZ,OAAO;AAAA,QACT;AAAA,MAAA,CACD;AAAA,IACH;AAEA,WAAO,IAAI,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;"}
|
|
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: [\n 'childNodes',\n 'parentNode',\n 'parentElement',\n 'textContent',\n 'ownerDocument',\n ] 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 ownerDocument(n: Node): Document | null {\n return getUntaintedAccessor('Node', n, 'ownerDocument');\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 ownerDocument,\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;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY,CAAC,QAAQ,aAAa;AAAA,EAClC,SAAS,CAAC,cAAc,iBAAiB,kBAAkB;AAAA,EAC3D,kBAAkB,CAAA;AACpB;AAEA,MAAM,kBAAkB;AAAA,EACtB,MAAM,CAAC,YAAY,aAAa;AAAA,EAChC,YAAY,CAAC,cAAc;AAAA,EAC3B,SAAS,CAAC;AAAA,EACV,kBAAkB,CAAC,aAAa;AAClC;AAEA,MAAM,yBAAsD,CAAC;AAetD,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;AAAA,IAC3B;AAAA,IAEE,cAAc;AAAA,MAAM,CAAC,aACnB;AAvDR;AAuDQ;AAAA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Y,WAAmC;AAC3E,SAAO,qBAAqB,WAAW,GAAG,eAAe,EAAE,SAAS;AACtE;AAEgB,SAAA,iBACd,GACA,WACqB;AACrB,SAAO,qBAAqB,WAAW,GAAG,kBAAkB,EAAE,SAAS;AACzE;AAEO,SAAS,uBAA8E;AACrF,SAAA,sBAAsB,kBAAkB,EAAE;AACnD;AAGgB,SAAA,MACd,QACA,MACA,aACY;AACR,MAAA;AACE,QAAA,EAAE,QAAQ,SAAS;AACrB,aAAO,MAAM;AAAA,MAEb;AAAA,IAAA;AAGI,UAAA,WAAW,OAAO,IAAI;AACtB,UAAA,UAAU,YAAY,QAAQ;AAIhC,QAAA,OAAO,YAAY,YAAY;AAEzB,cAAA,YAAY,QAAQ,aAAa,CAAC;AAC1C,aAAO,iBAAiB,SAAS;AAAA,QAC/B,oBAAoB;AAAA,UAClB,YAAY;AAAA,UACZ,OAAO;AAAA,QAAA;AAAA,MACT,CACD;AAAA,IAAA;AAGH,WAAO,IAAI,IAAI;AAEf,WAAO,MAAM;AACX,aAAO,IAAI,IAAI;AAAA,IACjB;AAAA,EAAA,QACM;AACN,WAAO,MAAM;AAAA,IAEb;AAAA,EAAA;AAIJ;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;AAAA,EACA,kBAAkB;AAAA,EAClB;AACF;"}
|
package/dist/utils.umd.cjs
CHANGED
|
@@ -14,7 +14,13 @@ var module = { exports };
|
|
|
14
14
|
"use strict";
|
|
15
15
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
16
16
|
const testableAccessors = {
|
|
17
|
-
Node: [
|
|
17
|
+
Node: [
|
|
18
|
+
"childNodes",
|
|
19
|
+
"parentNode",
|
|
20
|
+
"parentElement",
|
|
21
|
+
"textContent",
|
|
22
|
+
"ownerDocument"
|
|
23
|
+
],
|
|
18
24
|
ShadowRoot: ["host", "styleSheets"],
|
|
19
25
|
Element: ["shadowRoot", "querySelector", "querySelectorAll"],
|
|
20
26
|
MutationObserver: []
|
|
@@ -103,6 +109,9 @@ function getUntaintedMethod(key, instance, method) {
|
|
|
103
109
|
untaintedMethodCache[cacheKey] = untaintedMethod;
|
|
104
110
|
return untaintedMethod.bind(instance);
|
|
105
111
|
}
|
|
112
|
+
function ownerDocument(n) {
|
|
113
|
+
return getUntaintedAccessor("Node", n, "ownerDocument");
|
|
114
|
+
}
|
|
106
115
|
function childNodes(n) {
|
|
107
116
|
return getUntaintedAccessor("Node", n, "childNodes");
|
|
108
117
|
}
|
|
@@ -168,6 +177,7 @@ function patch(source, name, replacement) {
|
|
|
168
177
|
}
|
|
169
178
|
}
|
|
170
179
|
const index = {
|
|
180
|
+
ownerDocument,
|
|
171
181
|
childNodes,
|
|
172
182
|
parentNode,
|
|
173
183
|
parentElement,
|
|
@@ -192,6 +202,7 @@ exports.getUntaintedPrototype = getUntaintedPrototype;
|
|
|
192
202
|
exports.host = host;
|
|
193
203
|
exports.isAngularZonePresent = isAngularZonePresent;
|
|
194
204
|
exports.mutationObserverCtor = mutationObserverCtor;
|
|
205
|
+
exports.ownerDocument = ownerDocument;
|
|
195
206
|
exports.parentElement = parentElement;
|
|
196
207
|
exports.parentNode = parentNode;
|
|
197
208
|
exports.patch = patch;
|
package/dist/utils.umd.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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'
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;AAcA,MAAM,oBAAoB;EACxB,MAAM
|
|
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: [\n 'childNodes',\n 'parentNode',\n 'parentElement',\n 'textContent',\n 'ownerDocument',\n ] 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 ownerDocument(n: Node): Document | null {\n return getUntaintedAccessor('Node', n, 'ownerDocument');\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 ownerDocument,\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,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,SACM;AACN,WAAO,MAAM;IAEb;EAAA;AAIJ;AAEA,MAAe,QAAA;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,kBAAkB;EAClB;AACF;;;;;;;;;;;;;;;;;;;;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/utils.umd.min.cjs
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
}(this, () => {
|
|
12
12
|
var exports = {};
|
|
13
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(
|
|
14
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g={Node:["childNodes","parentNode","parentElement","textContent","ownerDocument"],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(c=>{var s,a;return!!((a=(s=Object.getOwnPropertyDescriptor(o,c))==null?void 0:s.get)!=null&&a.toString().includes("[native code]"))})),u=t in b?b[t]:void 0,d=!!(u&&u.every(c=>{var s;return typeof o[c]=="function"&&((s=o[c])==null?void 0:s.toString().includes("[native code]"))}));if(r&&d&&!v())return l[t]=e.prototype,e.prototype;try{const c=document.createElement("iframe");document.body.appendChild(c);const s=c.contentWindow;if(!s)return e.prototype;const a=s[t].prototype;return document.body.removeChild(c),a?l[t]=a:o}catch(c){return o}}const f={};function i(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 i("Node",t,"ownerDocument")}function m(t){return i("Node",t,"childNodes")}function S(t){return i("Node",t,"parentNode")}function w(t){return i("Node",t,"parentElement")}function O(t){return i("Node",t,"textContent")}function P(t,e){return y("Node",t,"contains")(e)}function A(t){return y("Node",t,"getRootNode")()}function R(t){return!t||!("host"in t)?null:i("ShadowRoot",t,"host")}function E(t){return t.styleSheets}function M(t){return!t||!("shadowRoot"in t)?null:i("Element",t,"shadowRoot")}function _(t,e){return i("Element",t,"querySelector")(e)}function C(t,e){return i("Element",t,"querySelectorAll")(e)}function q(){return p("MutationObserver").constructor}function U(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 j={ownerDocument:N,childNodes:m,parentNode:S,parentElement:w,textContent:O,contains:P,getRootNode:A,host:R,styleSheets:E,shadowRoot:M,querySelector:_,querySelectorAll:C,mutationObserver:q,patch:U};exports.childNodes=m;exports.contains=P;exports.default=j;exports.getRootNode=A;exports.getUntaintedAccessor=i;exports.getUntaintedMethod=y;exports.getUntaintedPrototype=p;exports.host=R;exports.isAngularZonePresent=v;exports.mutationObserverCtor=q;exports.ownerDocument=N;exports.parentElement=w;exports.parentNode=S;exports.patch=U;exports.querySelector=_;exports.querySelectorAll=C;exports.shadowRoot=M;exports.styleSheets=E;exports.textContent=O;
|
|
15
15
|
if (typeof module.exports == "object" && typeof exports == "object") {
|
|
16
16
|
var __cp = (to, from, except, desc) => {
|
|
17
17
|
if ((from && typeof from === "object") || typeof from === "function") {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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'
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;4GAcA,MAAMA,EAAoB,CACxB,KAAM,
|
|
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", "
|
|
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: [\n 'childNodes',\n 'parentNode',\n 'parentElement',\n 'textContent',\n 'ownerDocument',\n ] 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 ownerDocument(n: Node): Document | null {\n return getUntaintedAccessor('Node', n, 'ownerDocument');\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 ownerDocument,\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,CACJ,aACA,aACA,gBACA,cACA,eACF,EACA,WAAY,CAAC,OAAQ,aAAa,EAClC,QAAS,CAAC,aAAc,gBAAiB,kBAAkB,EAC3D,iBAAkB,CAAA,CACpB,EAEMC,EAAkB,CACtB,KAAM,CAAC,WAAY,aAAa,EAChC,WAAY,CAAC,cAAc,EAC3B,QAAS,CAAC,EACV,iBAAkB,CAAC,aAAa,CAClC,EAEMC,EAAsD,CAAC,EAehDC,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,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AY,CACnE,CAEgB,SAAAW,EAAcX,EAAYY,EAAmC,CAC3E,OAAOrB,EAAqB,UAAWS,EAAG,eAAe,EAAEY,CAAS,CACtE,CAEgB,SAAAC,EACdb,EACAY,EACqB,CACrB,OAAOrB,EAAqB,UAAWS,EAAG,kBAAkB,EAAEY,CAAS,CACzE,CAEO,SAASE,GAA8E,CACrF,OAAAxC,EAAsB,kBAAkB,EAAE,WACnD,CAGgB,SAAAyC,EACdC,EACAC,EACAC,EACY,CACR,GAAA,CACE,GAAA,EAAED,KAAQD,GACZ,MAAO,IAAM,CAEb,EAGI,MAAAG,EAAWH,EAAOC,CAAI,EACtBG,EAAUF,EAAYC,CAAQ,EAIhC,OAAA,OAAOC,GAAY,aAEbA,EAAA,UAAYA,EAAQ,WAAa,CAAC,EAC1C,OAAO,iBAAiBA,EAAS,CAC/B,mBAAoB,CAClB,WAAY,GACZ,MAAOD,CAAA,CACT,CACD,GAGHH,EAAOC,CAAI,EAAIG,EAER,IAAM,CACXJ,EAAOC,CAAI,EAAIE,CACjB,CAAA,OACM9B,EAAA,CACN,MAAO,IAAM,CAEb,CAAA,CAIJ,CAEA,MAAegC,EAAA,CACb,cAAAtB,EACA,WAAAE,EACA,WAAAC,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", "ownerDocument", "n", "childNodes", "parentNode", "parentElement", "textContent", "contains", "other", "getRootNode", "host", "styleSheets", "shadowRoot", "querySelector", "selectors", "querySelectorAll", "mutationObserverCtor", "patch", "source", "name", "replacement", "original", "wrapped", "index"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betterbugs/utils",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.21",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -43,11 +43,12 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
|
+
"umd",
|
|
46
47
|
"dist",
|
|
47
48
|
"package.json"
|
|
48
49
|
],
|
|
49
50
|
"devDependencies": {
|
|
50
|
-
"vite": "^
|
|
51
|
+
"vite": "^6.0.1",
|
|
51
52
|
"vite-plugin-dts": "^3.8.1"
|
|
52
53
|
},
|
|
53
54
|
"dependencies": {}
|
package/umd/utils.js
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
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: [
|
|
18
|
+
"childNodes",
|
|
19
|
+
"parentNode",
|
|
20
|
+
"parentElement",
|
|
21
|
+
"textContent",
|
|
22
|
+
"ownerDocument"
|
|
23
|
+
],
|
|
24
|
+
ShadowRoot: ["host", "styleSheets"],
|
|
25
|
+
Element: ["shadowRoot", "querySelector", "querySelectorAll"],
|
|
26
|
+
MutationObserver: []
|
|
27
|
+
};
|
|
28
|
+
const testableMethods = {
|
|
29
|
+
Node: ["contains", "getRootNode"],
|
|
30
|
+
ShadowRoot: ["getSelection"],
|
|
31
|
+
Element: [],
|
|
32
|
+
MutationObserver: ["constructor"]
|
|
33
|
+
};
|
|
34
|
+
const untaintedBasePrototype = {};
|
|
35
|
+
const isAngularZonePresent = () => {
|
|
36
|
+
return !!globalThis.Zone;
|
|
37
|
+
};
|
|
38
|
+
function getUntaintedPrototype(key) {
|
|
39
|
+
if (untaintedBasePrototype[key])
|
|
40
|
+
return untaintedBasePrototype[key];
|
|
41
|
+
const defaultObj = globalThis[key];
|
|
42
|
+
const defaultPrototype = defaultObj.prototype;
|
|
43
|
+
const accessorNames = key in testableAccessors ? testableAccessors[key] : void 0;
|
|
44
|
+
const isUntaintedAccessors = Boolean(
|
|
45
|
+
accessorNames && // @ts-expect-error 2345
|
|
46
|
+
accessorNames.every(
|
|
47
|
+
(accessor) => {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
return Boolean(
|
|
50
|
+
(_b = (_a = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) == null ? void 0 : _a.get) == null ? void 0 : _b.toString().includes("[native code]")
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
const methodNames = key in testableMethods ? testableMethods[key] : void 0;
|
|
56
|
+
const isUntaintedMethods = Boolean(
|
|
57
|
+
methodNames && methodNames.every(
|
|
58
|
+
// @ts-expect-error 2345
|
|
59
|
+
(method) => {
|
|
60
|
+
var _a;
|
|
61
|
+
return typeof defaultPrototype[method] === "function" && ((_a = defaultPrototype[method]) == null ? void 0 : _a.toString().includes("[native code]"));
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
if (isUntaintedAccessors && isUntaintedMethods && !isAngularZonePresent()) {
|
|
66
|
+
untaintedBasePrototype[key] = defaultObj.prototype;
|
|
67
|
+
return defaultObj.prototype;
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const iframeEl = document.createElement("iframe");
|
|
71
|
+
document.body.appendChild(iframeEl);
|
|
72
|
+
const win = iframeEl.contentWindow;
|
|
73
|
+
if (!win) return defaultObj.prototype;
|
|
74
|
+
const untaintedObject = win[key].prototype;
|
|
75
|
+
document.body.removeChild(iframeEl);
|
|
76
|
+
if (!untaintedObject) return defaultPrototype;
|
|
77
|
+
return untaintedBasePrototype[key] = untaintedObject;
|
|
78
|
+
} catch (e) {
|
|
79
|
+
return defaultPrototype;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const untaintedAccessorCache = {};
|
|
83
|
+
function getUntaintedAccessor(key, instance, accessor) {
|
|
84
|
+
var _a;
|
|
85
|
+
const cacheKey = `${key}.${String(accessor)}`;
|
|
86
|
+
if (untaintedAccessorCache[cacheKey])
|
|
87
|
+
return untaintedAccessorCache[cacheKey].call(
|
|
88
|
+
instance
|
|
89
|
+
);
|
|
90
|
+
const untaintedPrototype = getUntaintedPrototype(key);
|
|
91
|
+
const untaintedAccessor = (_a = Object.getOwnPropertyDescriptor(
|
|
92
|
+
untaintedPrototype,
|
|
93
|
+
accessor
|
|
94
|
+
)) == null ? void 0 : _a.get;
|
|
95
|
+
if (!untaintedAccessor) return instance[accessor];
|
|
96
|
+
untaintedAccessorCache[cacheKey] = untaintedAccessor;
|
|
97
|
+
return untaintedAccessor.call(instance);
|
|
98
|
+
}
|
|
99
|
+
const untaintedMethodCache = {};
|
|
100
|
+
function getUntaintedMethod(key, instance, method) {
|
|
101
|
+
const cacheKey = `${key}.${String(method)}`;
|
|
102
|
+
if (untaintedMethodCache[cacheKey])
|
|
103
|
+
return untaintedMethodCache[cacheKey].bind(
|
|
104
|
+
instance
|
|
105
|
+
);
|
|
106
|
+
const untaintedPrototype = getUntaintedPrototype(key);
|
|
107
|
+
const untaintedMethod = untaintedPrototype[method];
|
|
108
|
+
if (typeof untaintedMethod !== "function") return instance[method];
|
|
109
|
+
untaintedMethodCache[cacheKey] = untaintedMethod;
|
|
110
|
+
return untaintedMethod.bind(instance);
|
|
111
|
+
}
|
|
112
|
+
function ownerDocument(n) {
|
|
113
|
+
return getUntaintedAccessor("Node", n, "ownerDocument");
|
|
114
|
+
}
|
|
115
|
+
function childNodes(n) {
|
|
116
|
+
return getUntaintedAccessor("Node", n, "childNodes");
|
|
117
|
+
}
|
|
118
|
+
function parentNode(n) {
|
|
119
|
+
return getUntaintedAccessor("Node", n, "parentNode");
|
|
120
|
+
}
|
|
121
|
+
function parentElement(n) {
|
|
122
|
+
return getUntaintedAccessor("Node", n, "parentElement");
|
|
123
|
+
}
|
|
124
|
+
function textContent(n) {
|
|
125
|
+
return getUntaintedAccessor("Node", n, "textContent");
|
|
126
|
+
}
|
|
127
|
+
function contains(n, other) {
|
|
128
|
+
return getUntaintedMethod("Node", n, "contains")(other);
|
|
129
|
+
}
|
|
130
|
+
function getRootNode(n) {
|
|
131
|
+
return getUntaintedMethod("Node", n, "getRootNode")();
|
|
132
|
+
}
|
|
133
|
+
function host(n) {
|
|
134
|
+
if (!n || !("host" in n)) return null;
|
|
135
|
+
return getUntaintedAccessor("ShadowRoot", n, "host");
|
|
136
|
+
}
|
|
137
|
+
function styleSheets(n) {
|
|
138
|
+
return n.styleSheets;
|
|
139
|
+
}
|
|
140
|
+
function shadowRoot(n) {
|
|
141
|
+
if (!n || !("shadowRoot" in n)) return null;
|
|
142
|
+
return getUntaintedAccessor("Element", n, "shadowRoot");
|
|
143
|
+
}
|
|
144
|
+
function querySelector(n, selectors) {
|
|
145
|
+
return getUntaintedAccessor("Element", n, "querySelector")(selectors);
|
|
146
|
+
}
|
|
147
|
+
function querySelectorAll(n, selectors) {
|
|
148
|
+
return getUntaintedAccessor("Element", n, "querySelectorAll")(selectors);
|
|
149
|
+
}
|
|
150
|
+
function mutationObserverCtor() {
|
|
151
|
+
return getUntaintedPrototype("MutationObserver").constructor;
|
|
152
|
+
}
|
|
153
|
+
function patch(source, name, replacement) {
|
|
154
|
+
try {
|
|
155
|
+
if (!(name in source)) {
|
|
156
|
+
return () => {
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const original = source[name];
|
|
160
|
+
const wrapped = replacement(original);
|
|
161
|
+
if (typeof wrapped === "function") {
|
|
162
|
+
wrapped.prototype = wrapped.prototype || {};
|
|
163
|
+
Object.defineProperties(wrapped, {
|
|
164
|
+
__rrweb_original__: {
|
|
165
|
+
enumerable: false,
|
|
166
|
+
value: original
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
source[name] = wrapped;
|
|
171
|
+
return () => {
|
|
172
|
+
source[name] = original;
|
|
173
|
+
};
|
|
174
|
+
} catch (e) {
|
|
175
|
+
return () => {
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const index = {
|
|
180
|
+
ownerDocument,
|
|
181
|
+
childNodes,
|
|
182
|
+
parentNode,
|
|
183
|
+
parentElement,
|
|
184
|
+
textContent,
|
|
185
|
+
contains,
|
|
186
|
+
getRootNode,
|
|
187
|
+
host,
|
|
188
|
+
styleSheets,
|
|
189
|
+
shadowRoot,
|
|
190
|
+
querySelector,
|
|
191
|
+
querySelectorAll,
|
|
192
|
+
mutationObserver: mutationObserverCtor,
|
|
193
|
+
patch
|
|
194
|
+
};
|
|
195
|
+
exports.childNodes = childNodes;
|
|
196
|
+
exports.contains = contains;
|
|
197
|
+
exports.default = index;
|
|
198
|
+
exports.getRootNode = getRootNode;
|
|
199
|
+
exports.getUntaintedAccessor = getUntaintedAccessor;
|
|
200
|
+
exports.getUntaintedMethod = getUntaintedMethod;
|
|
201
|
+
exports.getUntaintedPrototype = getUntaintedPrototype;
|
|
202
|
+
exports.host = host;
|
|
203
|
+
exports.isAngularZonePresent = isAngularZonePresent;
|
|
204
|
+
exports.mutationObserverCtor = mutationObserverCtor;
|
|
205
|
+
exports.ownerDocument = ownerDocument;
|
|
206
|
+
exports.parentElement = parentElement;
|
|
207
|
+
exports.parentNode = parentNode;
|
|
208
|
+
exports.patch = patch;
|
|
209
|
+
exports.querySelector = querySelector;
|
|
210
|
+
exports.querySelectorAll = querySelectorAll;
|
|
211
|
+
exports.shadowRoot = shadowRoot;
|
|
212
|
+
exports.styleSheets = styleSheets;
|
|
213
|
+
exports.textContent = textContent;
|
|
214
|
+
if (typeof module.exports == "object" && typeof exports == "object") {
|
|
215
|
+
var __cp = (to, from, except, desc) => {
|
|
216
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
217
|
+
for (let key of Object.getOwnPropertyNames(from)) {
|
|
218
|
+
if (!Object.prototype.hasOwnProperty.call(to, key) && key !== except)
|
|
219
|
+
Object.defineProperty(to, key, {
|
|
220
|
+
get: () => from[key],
|
|
221
|
+
enumerable: !(desc = Object.getOwnPropertyDescriptor(from, key)) || desc.enumerable,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return to;
|
|
226
|
+
};
|
|
227
|
+
module.exports = __cp(module.exports, exports);
|
|
228
|
+
}
|
|
229
|
+
return module.exports;
|
|
230
|
+
}))
|
|
231
|
+
//# sourceMappingURL=utils.umd.cjs.map
|
package/umd/utils.min.js
ADDED
|
@@ -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","ownerDocument"],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(c=>{var s,a;return!!((a=(s=Object.getOwnPropertyDescriptor(o,c))==null?void 0:s.get)!=null&&a.toString().includes("[native code]"))})),u=t in b?b[t]:void 0,d=!!(u&&u.every(c=>{var s;return typeof o[c]=="function"&&((s=o[c])==null?void 0:s.toString().includes("[native code]"))}));if(r&&d&&!v())return l[t]=e.prototype,e.prototype;try{const c=document.createElement("iframe");document.body.appendChild(c);const s=c.contentWindow;if(!s)return e.prototype;const a=s[t].prototype;return document.body.removeChild(c),a?l[t]=a:o}catch(c){return o}}const f={};function i(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 i("Node",t,"ownerDocument")}function m(t){return i("Node",t,"childNodes")}function S(t){return i("Node",t,"parentNode")}function w(t){return i("Node",t,"parentElement")}function O(t){return i("Node",t,"textContent")}function P(t,e){return y("Node",t,"contains")(e)}function A(t){return y("Node",t,"getRootNode")()}function R(t){return!t||!("host"in t)?null:i("ShadowRoot",t,"host")}function E(t){return t.styleSheets}function M(t){return!t||!("shadowRoot"in t)?null:i("Element",t,"shadowRoot")}function _(t,e){return i("Element",t,"querySelector")(e)}function C(t,e){return i("Element",t,"querySelectorAll")(e)}function q(){return p("MutationObserver").constructor}function U(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 j={ownerDocument:N,childNodes:m,parentNode:S,parentElement:w,textContent:O,contains:P,getRootNode:A,host:R,styleSheets:E,shadowRoot:M,querySelector:_,querySelectorAll:C,mutationObserver:q,patch:U};exports.childNodes=m;exports.contains=P;exports.default=j;exports.getRootNode=A;exports.getUntaintedAccessor=i;exports.getUntaintedMethod=y;exports.getUntaintedPrototype=p;exports.host=R;exports.isAngularZonePresent=v;exports.mutationObserverCtor=q;exports.ownerDocument=N;exports.parentElement=w;exports.parentNode=S;exports.patch=U;exports.querySelector=_;exports.querySelectorAll=C;exports.shadowRoot=M;exports.styleSheets=E;exports.textContent=O;
|
|
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
|