@openreplay/tracker 7.0.1-beta.2 → 7.0.2-beta.1
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/CHANGELOG.md +6 -0
- package/cjs/app/index.js +17 -22
- package/cjs/app/observer/iframe_offsets.js +4 -2
- package/cjs/app/observer/observer.js +1 -1
- package/cjs/index.js +1 -1
- package/cjs/modules/axiosSpy.d.ts +53 -0
- package/cjs/modules/axiosSpy.js +102 -0
- package/cjs/modules/constructedStyleSheets.js +2 -5
- package/cjs/modules/input.js +11 -1
- package/cjs/modules/mouse.js +12 -21
- package/cjs/modules/network.d.ts +4 -1
- package/cjs/modules/network.js +21 -9
- package/cjs/utils.js +2 -1
- package/cjs/vendors/finder/finder.js +2 -2
- package/lib/app/index.js +17 -22
- package/lib/app/observer/iframe_offsets.js +4 -2
- package/lib/app/observer/observer.js +1 -1
- package/lib/common/tsconfig.tsbuildinfo +1 -1
- package/lib/index.js +1 -1
- package/lib/modules/axiosSpy.d.ts +53 -0
- package/lib/modules/axiosSpy.js +99 -0
- package/lib/modules/constructedStyleSheets.js +2 -5
- package/lib/modules/input.js +11 -1
- package/lib/modules/mouse.js +12 -21
- package/lib/modules/network.d.ts +4 -1
- package/lib/modules/network.js +21 -9
- package/lib/utils.js +2 -1
- package/lib/vendors/finder/finder.js +2 -2
- package/package.json +2 -2
- package/tsconfig-base.json +2 -2
package/lib/modules/mouse.js
CHANGED
|
@@ -2,21 +2,16 @@ import { hasTag, isSVGElement, isDocument } from '../app/guards.js';
|
|
|
2
2
|
import { normSpaces, hasOpenreplayAttribute, getLabelAttribute, now } from '../utils.js';
|
|
3
3
|
import { MouseMove, MouseClick, MouseThrashing } from '../app/messages.gen.js';
|
|
4
4
|
import { getInputLabel } from './input.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
async function _getSelector(target, document, options) {
|
|
9
|
-
if (!finderLib) {
|
|
10
|
-
const { finder } = await import('@medv/finder');
|
|
11
|
-
finderLib = finder;
|
|
12
|
-
}
|
|
13
|
-
return finderLib(target, {
|
|
5
|
+
import { finder } from '@medv/finder';
|
|
6
|
+
function _getSelector(target, document, options) {
|
|
7
|
+
const selector = finder(target, {
|
|
14
8
|
root: document.body,
|
|
15
9
|
seedMinLength: 3,
|
|
16
|
-
optimizedMinLength: options
|
|
17
|
-
threshold: options
|
|
18
|
-
maxNumberOfTries: options
|
|
10
|
+
optimizedMinLength: (options === null || options === void 0 ? void 0 : options.minSelectorDepth) || 2,
|
|
11
|
+
threshold: (options === null || options === void 0 ? void 0 : options.nthThreshold) || 1000,
|
|
12
|
+
maxNumberOfTries: (options === null || options === void 0 ? void 0 : options.maxOptimiseTries) || 10000,
|
|
19
13
|
});
|
|
14
|
+
return selector;
|
|
20
15
|
}
|
|
21
16
|
function isClickable(element) {
|
|
22
17
|
const tag = element.tagName.toUpperCase();
|
|
@@ -136,12 +131,8 @@ export default function (app, options) {
|
|
|
136
131
|
}
|
|
137
132
|
};
|
|
138
133
|
const patchDocument = (document, topframe = false) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return selectorMap[id];
|
|
142
|
-
}
|
|
143
|
-
const selector = await _getSelector(target, document, options);
|
|
144
|
-
return selector;
|
|
134
|
+
function getSelector(id, target, options) {
|
|
135
|
+
return (selectorMap[id] = selectorMap[id] || _getSelector(target, document, options));
|
|
145
136
|
}
|
|
146
137
|
const attachListener = topframe
|
|
147
138
|
? app.attachEventListener.bind(app) // attached/removed on start/stop
|
|
@@ -165,7 +156,7 @@ export default function (app, options) {
|
|
|
165
156
|
directionChangeCount++;
|
|
166
157
|
}
|
|
167
158
|
}, false);
|
|
168
|
-
attachListener(document, 'click',
|
|
159
|
+
attachListener(document, 'click', (e) => {
|
|
169
160
|
const target = getTarget(e.target, document);
|
|
170
161
|
if ((!e.clientX && !e.clientY) || target === null) {
|
|
171
162
|
return;
|
|
@@ -173,7 +164,7 @@ export default function (app, options) {
|
|
|
173
164
|
const id = app.nodes.getID(target);
|
|
174
165
|
if (id !== undefined) {
|
|
175
166
|
sendMouseMove();
|
|
176
|
-
app.send(MouseClick(id, mouseTarget === target ? Math.round(performance.now() - mouseTargetTime) : 0, getTargetLabel(target), isClickable(target) && !disableClickmaps ?
|
|
167
|
+
app.send(MouseClick(id, mouseTarget === target ? Math.round(performance.now() - mouseTargetTime) : 0, getTargetLabel(target), isClickable(target) && !disableClickmaps ? getSelector(id, target, options) : ''), true);
|
|
177
168
|
}
|
|
178
169
|
mouseTarget = null;
|
|
179
170
|
});
|
|
@@ -184,5 +175,5 @@ export default function (app, options) {
|
|
|
184
175
|
}
|
|
185
176
|
});
|
|
186
177
|
patchDocument(document, true);
|
|
187
|
-
app.ticker.attach(sendMouseMove, options
|
|
178
|
+
app.ticker.attach(sendMouseMove, (options === null || options === void 0 ? void 0 : options.trackingOffset) || 7);
|
|
188
179
|
}
|
package/lib/modules/network.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type App from '../app/index.js';
|
|
2
|
+
import type { AxiosInstance } from './axiosSpy.js';
|
|
2
3
|
type XHRRequestBody = Parameters<XMLHttpRequest['send']>[0];
|
|
3
4
|
type FetchRequestBody = RequestInit['body'];
|
|
4
5
|
interface RequestData {
|
|
@@ -9,7 +10,7 @@ interface ResponseData {
|
|
|
9
10
|
body: any;
|
|
10
11
|
headers: Record<string, string>;
|
|
11
12
|
}
|
|
12
|
-
interface RequestResponseData {
|
|
13
|
+
export interface RequestResponseData {
|
|
13
14
|
readonly status: number;
|
|
14
15
|
readonly method: string;
|
|
15
16
|
url: string;
|
|
@@ -22,7 +23,9 @@ export interface Options {
|
|
|
22
23
|
failuresOnly: boolean;
|
|
23
24
|
ignoreHeaders: Array<string> | boolean;
|
|
24
25
|
capturePayload: boolean;
|
|
26
|
+
captureInIframes: boolean;
|
|
25
27
|
sanitizer?: Sanitizer;
|
|
28
|
+
axiosInstances?: Array<AxiosInstance>;
|
|
26
29
|
}
|
|
27
30
|
export default function (app: App, opts?: Partial<Options>): void;
|
|
28
31
|
export {};
|
package/lib/modules/network.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NetworkRequest } from '../app/messages.gen.js';
|
|
2
2
|
import { getTimeOrigin } from '../utils.js';
|
|
3
|
+
import axiosSpy from './axiosSpy.js';
|
|
3
4
|
function getXHRRequestDataObject(xhr) {
|
|
4
5
|
// @ts-ignore this is 3x faster than using Map<XHR, XHRRequestData>
|
|
5
6
|
if (!xhr.__or_req_data__) {
|
|
@@ -18,6 +19,8 @@ export default function (app, opts = {}) {
|
|
|
18
19
|
ignoreHeaders: ['Cookie', 'Set-Cookie', 'Authorization'],
|
|
19
20
|
capturePayload: false,
|
|
20
21
|
sessionTokenHeader: false,
|
|
22
|
+
captureInIframes: true,
|
|
23
|
+
axiosInstances: undefined,
|
|
21
24
|
}, opts);
|
|
22
25
|
const ignoreHeaders = options.ignoreHeaders;
|
|
23
26
|
const isHIgnored = Array.isArray(ignoreHeaders)
|
|
@@ -44,7 +47,7 @@ export default function (app, opts = {}) {
|
|
|
44
47
|
try {
|
|
45
48
|
reqResInfo.response.body = JSON.parse(resBody);
|
|
46
49
|
}
|
|
47
|
-
catch { }
|
|
50
|
+
catch (_a) { }
|
|
48
51
|
}
|
|
49
52
|
return options.sanitizer(reqResInfo);
|
|
50
53
|
}
|
|
@@ -55,7 +58,7 @@ export default function (app, opts = {}) {
|
|
|
55
58
|
try {
|
|
56
59
|
r.body = JSON.stringify(r.body);
|
|
57
60
|
}
|
|
58
|
-
catch {
|
|
61
|
+
catch (_a) {
|
|
59
62
|
r.body = '<unable to stringify>';
|
|
60
63
|
app.notify.warn("Openreplay fetch couldn't stringify body:", r.body);
|
|
61
64
|
}
|
|
@@ -143,6 +146,8 @@ export default function (app, opts = {}) {
|
|
|
143
146
|
/* ====== <> ====== */
|
|
144
147
|
/* ====== XHR ====== */
|
|
145
148
|
const nativeOpen = context.XMLHttpRequest.prototype.open;
|
|
149
|
+
const nativeSetRequestHeader = context.XMLHttpRequest.prototype.setRequestHeader;
|
|
150
|
+
const nativeSend = context.XMLHttpRequest.prototype.send;
|
|
146
151
|
function trackXMLHttpReqOpen(initMethod, url) {
|
|
147
152
|
const xhr = this;
|
|
148
153
|
setSessionTokenHeader((name, value) => xhr.setRequestHeader(name, value));
|
|
@@ -159,7 +164,7 @@ export default function (app, opts = {}) {
|
|
|
159
164
|
.split('\r\n')
|
|
160
165
|
.map((h) => h.split(':'))
|
|
161
166
|
.filter((entry) => !isHIgnored(entry[0]))
|
|
162
|
-
.reduce((hds, [name, value]) => ({
|
|
167
|
+
.reduce((hds, [name, value]) => (Object.assign(Object.assign({}, hds), { [name]: value })), {})
|
|
163
168
|
: {};
|
|
164
169
|
const method = strMethod(initMethod);
|
|
165
170
|
const reqResInfo = sanitize({
|
|
@@ -184,16 +189,12 @@ export default function (app, opts = {}) {
|
|
|
184
189
|
//xhr.addEventListener('error', (e) => {})
|
|
185
190
|
return nativeOpen.apply(this, arguments);
|
|
186
191
|
}
|
|
187
|
-
context.XMLHttpRequest.prototype.open = trackXMLHttpReqOpen;
|
|
188
|
-
const nativeSend = context.XMLHttpRequest.prototype.send;
|
|
189
192
|
function trackXHRSend(body) {
|
|
190
193
|
const rdo = getXHRRequestDataObject(this);
|
|
191
194
|
rdo.body = body;
|
|
192
195
|
// @ts-ignore ??? this -> XMLHttpRequest
|
|
193
196
|
return nativeSend.apply(this, arguments);
|
|
194
197
|
}
|
|
195
|
-
context.XMLHttpRequest.prototype.send = trackXHRSend;
|
|
196
|
-
const nativeSetRequestHeader = context.XMLHttpRequest.prototype.setRequestHeader;
|
|
197
198
|
function trackSetReqHeader(name, value) {
|
|
198
199
|
if (!isHIgnored(name)) {
|
|
199
200
|
const rdo = getXHRRequestDataObject(this);
|
|
@@ -201,9 +202,20 @@ export default function (app, opts = {}) {
|
|
|
201
202
|
}
|
|
202
203
|
return nativeSetRequestHeader.apply(this, arguments);
|
|
203
204
|
}
|
|
204
|
-
|
|
205
|
+
if (!options.axiosInstances) {
|
|
206
|
+
context.XMLHttpRequest.prototype.open = trackXMLHttpReqOpen;
|
|
207
|
+
context.XMLHttpRequest.prototype.send = trackXHRSend;
|
|
208
|
+
context.XMLHttpRequest.prototype.setRequestHeader = trackSetReqHeader;
|
|
209
|
+
}
|
|
205
210
|
/* ====== <> ====== */
|
|
206
211
|
};
|
|
207
212
|
patchWindow(window);
|
|
208
|
-
|
|
213
|
+
if (options.axiosInstances) {
|
|
214
|
+
options.axiosInstances.forEach((axiosInstance) => {
|
|
215
|
+
axiosSpy(app, axiosInstance, options, sanitize, stringify);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
if (options.captureInIframes) {
|
|
219
|
+
app.observer.attachContextCallback(app.safe(patchWindow));
|
|
220
|
+
}
|
|
209
221
|
}
|
package/lib/utils.js
CHANGED
|
@@ -60,8 +60,9 @@ export function hasOpenreplayAttribute(e, attr) {
|
|
|
60
60
|
return false;
|
|
61
61
|
}
|
|
62
62
|
export function isIframeCrossdomain(e) {
|
|
63
|
+
var _a;
|
|
63
64
|
try {
|
|
64
|
-
return e.contentWindow
|
|
65
|
+
return ((_a = e.contentWindow) === null || _a === void 0 ? void 0 : _a.location.href) !== window.location.href;
|
|
65
66
|
}
|
|
66
67
|
catch (e) {
|
|
67
68
|
return true;
|
|
@@ -24,7 +24,7 @@ export function finder(input, options) {
|
|
|
24
24
|
threshold: 1000,
|
|
25
25
|
maxNumberOfTries: 10000,
|
|
26
26
|
};
|
|
27
|
-
config = {
|
|
27
|
+
config = Object.assign(Object.assign({}, defaults), options);
|
|
28
28
|
rootDocument = findRootDocument(config.root, defaults);
|
|
29
29
|
let path = bottomUpSearch(input, Limit.All, () => bottomUpSearch(input, Limit.Two, () => bottomUpSearch(input, Limit.One)));
|
|
30
30
|
if (path) {
|
|
@@ -267,7 +267,7 @@ const defaultOptions = {
|
|
|
267
267
|
wrap: false,
|
|
268
268
|
};
|
|
269
269
|
function cssesc(string, opt = {}) {
|
|
270
|
-
const options = {
|
|
270
|
+
const options = Object.assign(Object.assign({}, defaultOptions), opt);
|
|
271
271
|
if (options.quotes != 'single' && options.quotes != 'double') {
|
|
272
272
|
options.quotes = 'single';
|
|
273
273
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openreplay/tracker",
|
|
3
3
|
"description": "The OpenReplay tracker main package",
|
|
4
|
-
"version": "7.0.
|
|
4
|
+
"version": "7.0.2-beta.1",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"logging",
|
|
7
7
|
"replay"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"lint-staged": "^13.0.3",
|
|
41
41
|
"prettier": "^2.7.1",
|
|
42
42
|
"replace-in-files": "^2.0.3",
|
|
43
|
-
"rollup": "^2.
|
|
43
|
+
"rollup": "^2.59.0",
|
|
44
44
|
"rollup-plugin-terser": "^6.1.0",
|
|
45
45
|
"semver": "^6.3.0",
|
|
46
46
|
"ts-jest": "^29.0.3",
|
package/tsconfig-base.json
CHANGED