@cloudcare/browser-core 3.0.23 → 3.0.29
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/cjs/browser/addEventListener.js +9 -7
- package/cjs/browser/fetchObservable.js +5 -3
- package/cjs/console/consoleObservable.js +5 -1
- package/cjs/helper/errorTools.js +7 -3
- package/cjs/helper/instrumentMethod.js +4 -2
- package/cjs/helper/monitor.js +59 -0
- package/cjs/helper/readBytesFromStream.js +5 -3
- package/cjs/helper/timer.js +4 -2
- package/cjs/helper/tools.js +2 -20
- package/cjs/index.js +13 -0
- package/cjs/init.js +13 -19
- package/cjs/report/reportObservable.js +4 -3
- package/cjs/transport/batch.js +2 -2
- package/cjs/transport/httpRequest.js +5 -3
- package/esm/browser/addEventListener.js +8 -7
- package/esm/browser/fetchObservable.js +4 -3
- package/esm/console/consoleObservable.js +4 -1
- package/esm/helper/errorTools.js +6 -3
- package/esm/helper/instrumentMethod.js +3 -2
- package/esm/helper/monitor.js +40 -0
- package/esm/helper/readBytesFromStream.js +4 -3
- package/esm/helper/timer.js +3 -2
- package/esm/helper/tools.js +2 -18
- package/esm/index.js +1 -0
- package/esm/init.js +12 -18
- package/esm/report/reportObservable.js +3 -3
- package/esm/transport/batch.js +2 -2
- package/esm/transport/httpRequest.js +4 -3
- package/package.json +2 -2
- package/src/browser/addEventListener.js +8 -7
- package/src/browser/fetchObservable.js +12 -3
- package/src/console/consoleObservable.js +4 -2
- package/src/helper/errorTools.js +6 -5
- package/src/helper/instrumentMethod.js +5 -2
- package/src/helper/monitor.js +44 -0
- package/src/helper/observable.js +10 -8
- package/src/helper/readBytesFromStream.js +5 -5
- package/src/helper/timer.js +3 -3
- package/src/helper/tools.js +1 -17
- package/src/index.js +1 -0
- package/src/init.js +19 -21
- package/src/report/reportObservable.js +3 -2
- package/src/transport/batch.js +4 -4
- package/src/transport/httpRequest.js +5 -4
package/esm/helper/timer.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { getZoneJsOriginalValue } from './getZoneJsOriginalValue';
|
|
2
2
|
import { getGlobalObject } from '../init';
|
|
3
|
+
import { monitor } from './monitor';
|
|
3
4
|
export function setTimeout(callback, delay) {
|
|
4
|
-
return getZoneJsOriginalValue(getGlobalObject(), 'setTimeout')(callback, delay);
|
|
5
|
+
return getZoneJsOriginalValue(getGlobalObject(), 'setTimeout')(monitor(callback), delay);
|
|
5
6
|
}
|
|
6
7
|
export function clearTimeout(timeoutId) {
|
|
7
8
|
getZoneJsOriginalValue(getGlobalObject(), 'clearTimeout')(timeoutId);
|
|
8
9
|
}
|
|
9
10
|
export function setInterval(callback, delay) {
|
|
10
|
-
return getZoneJsOriginalValue(window, 'setInterval')(callback, delay);
|
|
11
|
+
return getZoneJsOriginalValue(window, 'setInterval')(monitor(callback), delay);
|
|
11
12
|
}
|
|
12
13
|
export function clearInterval(timeoutId) {
|
|
13
14
|
getZoneJsOriginalValue(window, 'clearInterval')(timeoutId);
|
package/esm/helper/tools.js
CHANGED
|
@@ -263,6 +263,8 @@ export var matchList = function matchList(list, value, useStartsWith) {
|
|
|
263
263
|
}; // https://github.com/jquery/jquery/blob/a684e6ba836f7c553968d7d026ed7941e1a612d8/src/selector/escapeSelector.js
|
|
264
264
|
|
|
265
265
|
export var cssEscape = function cssEscape(str) {
|
|
266
|
+
str = str + '';
|
|
267
|
+
|
|
266
268
|
if (window.CSS && window.CSS.escape) {
|
|
267
269
|
return window.CSS.escape(str);
|
|
268
270
|
} // eslint-disable-next-line no-control-regex
|
|
@@ -1664,24 +1666,6 @@ export function isNullUndefinedDefaultValue(data, defaultValue) {
|
|
|
1664
1666
|
return defaultValue;
|
|
1665
1667
|
}
|
|
1666
1668
|
}
|
|
1667
|
-
export function requestIdleCallback(callback, opts) {
|
|
1668
|
-
// Use 'requestIdleCallback' when available: it will throttle the mutation processing if the
|
|
1669
|
-
// browser is busy rendering frames (ex: when frames are below 60fps). When not available, the
|
|
1670
|
-
// fallback on 'requestAnimationFrame' will still ensure the mutations are processed after any
|
|
1671
|
-
// browser rendering process (Layout, Recalculate Style, etc.), so we can serialize DOM nodes
|
|
1672
|
-
// efficiently.
|
|
1673
|
-
if (window.requestIdleCallback) {
|
|
1674
|
-
var id = window.requestIdleCallback(callback, opts);
|
|
1675
|
-
return function () {
|
|
1676
|
-
return window.cancelIdleCallback(id);
|
|
1677
|
-
};
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1680
|
-
var id = window.requestAnimationFrame(callback);
|
|
1681
|
-
return function () {
|
|
1682
|
-
return window.cancelAnimationFrame(id);
|
|
1683
|
-
};
|
|
1684
|
-
}
|
|
1685
1669
|
export function objectHasValue(object, value) {
|
|
1686
1670
|
return some(keys(object), function (key) {
|
|
1687
1671
|
return object[key] === value;
|
package/esm/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * from './error/trackRuntimeError';
|
|
|
9
9
|
export * from './console/consoleObservable';
|
|
10
10
|
export * from './report/reportObservable';
|
|
11
11
|
export * from './helper/display';
|
|
12
|
+
export * from './helper/monitor';
|
|
12
13
|
export * from './helper/sanitize';
|
|
13
14
|
export * from './helper/eventEmitter';
|
|
14
15
|
export * from './helper/lifeCycle';
|
package/esm/init.js
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
onReady: function onReady(callback) {
|
|
7
|
-
callback();
|
|
8
|
-
}
|
|
9
|
-
});
|
|
10
|
-
return global;
|
|
11
|
-
}
|
|
3
|
+
import { each, assign } from './helper/tools';
|
|
4
|
+
import { setDebugMode } from './helper/monitor';
|
|
5
|
+
import { catchUserErrors } from './helper/catchUserErrors';
|
|
12
6
|
export function makePublicApi(stub) {
|
|
13
|
-
var publicApi =
|
|
7
|
+
var publicApi = assign({
|
|
14
8
|
onReady: function onReady(callback) {
|
|
15
9
|
callback();
|
|
16
10
|
}
|
|
17
|
-
}); // Add an "hidden" property to set debug mode. We define it that way to hide it
|
|
11
|
+
}, stub); // Add an "hidden" property to set debug mode. We define it that way to hide it
|
|
18
12
|
// as much as possible but of course it's not a real protection.
|
|
19
|
-
// Object.defineProperty(publicApi, '_setDebug', {
|
|
20
|
-
// get: function () {
|
|
21
|
-
// return setDebugMode
|
|
22
|
-
// },
|
|
23
|
-
// enumerable: false
|
|
24
|
-
// })
|
|
25
13
|
|
|
14
|
+
Object.defineProperty(publicApi, '_setDebug', {
|
|
15
|
+
get: function get() {
|
|
16
|
+
return setDebugMode;
|
|
17
|
+
},
|
|
18
|
+
enumerable: false
|
|
19
|
+
});
|
|
26
20
|
return publicApi;
|
|
27
21
|
}
|
|
28
22
|
export function defineGlobal(global, name, api) {
|
|
@@ -31,7 +25,7 @@ export function defineGlobal(global, name, api) {
|
|
|
31
25
|
|
|
32
26
|
if (existingGlobalVariable && existingGlobalVariable.q) {
|
|
33
27
|
each(existingGlobalVariable.q, function (fn) {
|
|
34
|
-
fn();
|
|
28
|
+
catchUserErrors(fn, 'onReady callback threw an error:')();
|
|
35
29
|
});
|
|
36
30
|
}
|
|
37
31
|
}
|
|
@@ -3,6 +3,7 @@ import { mergeObservables, Observable } from '../helper/observable';
|
|
|
3
3
|
import { includes, safeTruncate, filter, each } from '../helper/tools';
|
|
4
4
|
import { addEventListener } from '../browser/addEventListener';
|
|
5
5
|
import { DOM_EVENT } from '../helper/enums';
|
|
6
|
+
import { monitor } from '../helper/monitor';
|
|
6
7
|
export var RawReportType = {
|
|
7
8
|
intervention: 'intervention',
|
|
8
9
|
deprecation: 'deprecation',
|
|
@@ -32,12 +33,11 @@ function createReportObservable(reportTypes) {
|
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
var handleReports = function
|
|
36
|
+
var handleReports = monitor(function (reports) {
|
|
36
37
|
each(reports, function (report) {
|
|
37
38
|
observable.notify(buildRawReportFromReport(report));
|
|
38
39
|
});
|
|
39
|
-
};
|
|
40
|
-
|
|
40
|
+
});
|
|
41
41
|
var observer = new window.ReportingObserver(handleReports, {
|
|
42
42
|
types: reportTypes,
|
|
43
43
|
buffered: true
|
package/esm/transport/batch.js
CHANGED
|
@@ -66,10 +66,10 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
|
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
if (message.
|
|
69
|
+
if (message.context && isObject(message.context) && !isEmptyObject(message.context)) {
|
|
70
70
|
// 自定义tag, 存储成field
|
|
71
71
|
var _tagKeys = [];
|
|
72
|
-
each(message.
|
|
72
|
+
each(message.context, function (_value, _key) {
|
|
73
73
|
// 如果和之前tag重名,则舍弃
|
|
74
74
|
if (filterFileds.indexOf(_key) > -1) return;
|
|
75
75
|
filterFileds.push(_key);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { newRetryState, sendWithRetryStrategy } from './sendWithRetryStrategy';
|
|
2
2
|
import { addEventListener } from '../browser/addEventListener';
|
|
3
|
+
import { monitor } from '../helper/monitor';
|
|
3
4
|
/**
|
|
4
5
|
* Use POST request without content type to:
|
|
5
6
|
* - avoid CORS preflight requests
|
|
@@ -68,17 +69,17 @@ export function fetchKeepAliveStrategy(endpointUrl, bytesLimit, payload, onRespo
|
|
|
68
69
|
body: data,
|
|
69
70
|
keepalive: true,
|
|
70
71
|
mode: 'cors'
|
|
71
|
-
}).then(function (response) {
|
|
72
|
+
}).then(monitor(function (response) {
|
|
72
73
|
if (typeof onResponse === 'function') {
|
|
73
74
|
onResponse({
|
|
74
75
|
status: response.status,
|
|
75
76
|
type: response.type
|
|
76
77
|
});
|
|
77
78
|
}
|
|
78
|
-
}, function () {
|
|
79
|
+
}), monitor(function () {
|
|
79
80
|
// failed to queue the request
|
|
80
81
|
sendXHR(url, data, onResponse);
|
|
81
|
-
});
|
|
82
|
+
}));
|
|
82
83
|
} else {
|
|
83
84
|
sendXHR(url, data, onResponse);
|
|
84
85
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcare/browser-core",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.29",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,5 +20,5 @@
|
|
|
20
20
|
"author": "dataflux",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"description": "DataFlux RUM Web 端数据指标监控",
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "104fa066dfa70d87d54c3002bc6651c64d168478"
|
|
24
24
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { each } from '../helper/tools'
|
|
2
2
|
import { getZoneJsOriginalValue } from '../helper/getZoneJsOriginalValue'
|
|
3
|
+
import { monitor } from '../helper/monitor'
|
|
3
4
|
export function addEventListener(eventTarget, event, listener, options) {
|
|
4
5
|
return addEventListeners(eventTarget, [event], listener, options)
|
|
5
6
|
}
|
|
@@ -20,28 +21,28 @@ export function addEventListener(eventTarget, event, listener, options) {
|
|
|
20
21
|
* listened
|
|
21
22
|
*/
|
|
22
23
|
|
|
23
|
-
export function addEventListeners(eventTarget,
|
|
24
|
-
var wrappedListener =
|
|
24
|
+
export function addEventListeners(eventTarget, eventNames, listener, options) {
|
|
25
|
+
var wrappedListener = monitor(
|
|
25
26
|
options && options.once
|
|
26
27
|
? function (event) {
|
|
27
28
|
stop()
|
|
28
29
|
listener(event)
|
|
29
30
|
}
|
|
30
31
|
: listener
|
|
31
|
-
|
|
32
|
+
)
|
|
32
33
|
options =
|
|
33
34
|
options && options.passive
|
|
34
35
|
? { capture: options.capture, passive: options.passive }
|
|
35
36
|
: options && options.capture
|
|
36
37
|
var add = getZoneJsOriginalValue(eventTarget, 'addEventListener')
|
|
37
38
|
|
|
38
|
-
each(
|
|
39
|
-
add.call(eventTarget,
|
|
39
|
+
each(eventNames, function (eventName) {
|
|
40
|
+
add.call(eventTarget, eventName, wrappedListener, options)
|
|
40
41
|
})
|
|
41
42
|
var stop = function () {
|
|
42
43
|
var remove = getZoneJsOriginalValue(eventTarget, 'removeEventListener')
|
|
43
|
-
each(
|
|
44
|
-
remove.call(eventTarget,
|
|
44
|
+
each(eventNames, function (eventName) {
|
|
45
|
+
remove.call(eventTarget, eventName, wrappedListener, options)
|
|
45
46
|
})
|
|
46
47
|
}
|
|
47
48
|
return {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { instrumentMethod } from '../helper/instrumentMethod'
|
|
2
2
|
import { Observable } from '../helper/observable'
|
|
3
3
|
import { clocksNow } from '../helper/tools'
|
|
4
|
+
import { monitor, callMonitored } from '../helper/monitor'
|
|
4
5
|
import { normalizeUrl } from '../helper/urlPolyfill'
|
|
5
6
|
|
|
6
7
|
var fetchObservable
|
|
@@ -24,14 +25,22 @@ function createFetchObservable() {
|
|
|
24
25
|
function (originalFetch) {
|
|
25
26
|
return function (input, init) {
|
|
26
27
|
var responsePromise
|
|
27
|
-
var context = beforeSend
|
|
28
|
+
var context = callMonitored(beforeSend, null, [
|
|
29
|
+
observable,
|
|
30
|
+
input,
|
|
31
|
+
init
|
|
32
|
+
])
|
|
28
33
|
if (context) {
|
|
29
34
|
responsePromise = originalFetch.call(
|
|
30
35
|
this,
|
|
31
36
|
context.input,
|
|
32
37
|
context.init
|
|
33
38
|
)
|
|
34
|
-
afterSend
|
|
39
|
+
callMonitored(afterSend, null, [
|
|
40
|
+
observable,
|
|
41
|
+
responsePromise,
|
|
42
|
+
context
|
|
43
|
+
])
|
|
35
44
|
} else {
|
|
36
45
|
responsePromise = originalFetch.call(this, input, init)
|
|
37
46
|
}
|
|
@@ -91,5 +100,5 @@ function afterSend(observable, responsePromise, startContext) {
|
|
|
91
100
|
}
|
|
92
101
|
observable.notify(context)
|
|
93
102
|
}
|
|
94
|
-
responsePromise.then(reportFetch, reportFetch)
|
|
103
|
+
responsePromise.then(monitor(reportFetch), monitor(reportFetch))
|
|
95
104
|
}
|
|
@@ -8,7 +8,7 @@ import { mergeObservables, Observable } from '../helper/observable'
|
|
|
8
8
|
import { find, map } from '../helper/tools'
|
|
9
9
|
import { jsonStringify } from '../helper/serialisation/jsonStringify'
|
|
10
10
|
import { ConsoleApiName } from '../helper/display'
|
|
11
|
-
|
|
11
|
+
import { callMonitored } from '../helper/monitor'
|
|
12
12
|
var consoleObservablesByApi = {}
|
|
13
13
|
|
|
14
14
|
export function initConsoleObservable(apis) {
|
|
@@ -30,7 +30,9 @@ function createConsoleObservable(api) {
|
|
|
30
30
|
var params = [].slice.call(arguments)
|
|
31
31
|
originalConsoleApi.apply(console, arguments)
|
|
32
32
|
var handlingStack = createHandlingStack()
|
|
33
|
-
|
|
33
|
+
callMonitored(function () {
|
|
34
|
+
observable.notify(buildConsoleLog(params, api, handlingStack))
|
|
35
|
+
})
|
|
34
36
|
}
|
|
35
37
|
return function () {
|
|
36
38
|
console[api] = originalConsoleApi
|
package/src/helper/errorTools.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { each, noop } from './tools'
|
|
2
2
|
import { jsonStringify } from '../helper/serialisation/jsonStringify'
|
|
3
3
|
import { computeStackTrace } from '../tracekit'
|
|
4
|
-
|
|
4
|
+
import { callMonitored } from '../helper/monitor'
|
|
5
5
|
export var ErrorSource = {
|
|
6
6
|
AGENT: 'agent',
|
|
7
7
|
CONSOLE: 'console',
|
|
@@ -97,10 +97,11 @@ export function createHandlingStack() {
|
|
|
97
97
|
noop()
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
callMonitored(function () {
|
|
101
|
+
var stackTrace = computeStackTrace(error)
|
|
102
|
+
stackTrace.stack = stackTrace.stack.slice(internalFramesToSkip)
|
|
103
|
+
formattedStack = toStackTraceString(stackTrace)
|
|
104
|
+
})
|
|
104
105
|
|
|
105
106
|
return formattedStack
|
|
106
107
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { noop } from './tools'
|
|
2
2
|
import { setTimeout } from './timer'
|
|
3
|
+
import { callMonitored } from './monitor'
|
|
3
4
|
export function instrumentMethod(object, method, instrumentationFactory) {
|
|
4
5
|
var original = object[method]
|
|
5
6
|
|
|
@@ -29,14 +30,16 @@ export function instrumentMethodAndCallOriginal(object, method, aliasOption) {
|
|
|
29
30
|
return function () {
|
|
30
31
|
var result
|
|
31
32
|
if (aliasOption && aliasOption.before) {
|
|
32
|
-
aliasOption.before
|
|
33
|
+
callMonitored(aliasOption.before, this, arguments)
|
|
34
|
+
// aliasOption.before.apply(this, arguments)
|
|
33
35
|
}
|
|
34
36
|
if (typeof original === 'function') {
|
|
35
37
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
36
38
|
result = original.apply(this, arguments)
|
|
37
39
|
}
|
|
38
40
|
if (aliasOption && aliasOption.after) {
|
|
39
|
-
aliasOption.after
|
|
41
|
+
callMonitored(aliasOption.after, this, arguments)
|
|
42
|
+
// aliasOption.after.apply(this, arguments)
|
|
40
43
|
}
|
|
41
44
|
return result
|
|
42
45
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ConsoleApiName, display } from './display'
|
|
2
|
+
var onMonitorErrorCollected
|
|
3
|
+
var debugMode = false
|
|
4
|
+
|
|
5
|
+
export function startMonitorErrorCollection(newOnMonitorErrorCollected) {
|
|
6
|
+
onMonitorErrorCollected = newOnMonitorErrorCollected
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function setDebugMode(newDebugMode) {
|
|
10
|
+
debugMode = newDebugMode
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function resetMonitor() {
|
|
14
|
+
onMonitorErrorCollected = undefined
|
|
15
|
+
debugMode = false
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function monitor(fn) {
|
|
19
|
+
return function () {
|
|
20
|
+
return callMonitored(fn, this, arguments)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function callMonitored(fn, context, args) {
|
|
25
|
+
try {
|
|
26
|
+
return fn.apply(context, args)
|
|
27
|
+
} catch (e) {
|
|
28
|
+
displayIfDebugEnabled(ConsoleApiName.error, e)
|
|
29
|
+
if (onMonitorErrorCollected) {
|
|
30
|
+
try {
|
|
31
|
+
onMonitorErrorCollected(e)
|
|
32
|
+
} catch (e) {
|
|
33
|
+
displayIfDebugEnabled(ConsoleApiName.error, e)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function displayIfDebugEnabled(api) {
|
|
40
|
+
var args = [].slice.call(arguments, 1)
|
|
41
|
+
if (debugMode) {
|
|
42
|
+
display.apply(null, [api, '[MONITOR]'].concat(args))
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/helper/observable.js
CHANGED
|
@@ -12,14 +12,14 @@ _Observable.prototype = {
|
|
|
12
12
|
this.observers.push(f)
|
|
13
13
|
var _this = this
|
|
14
14
|
return {
|
|
15
|
-
unsubscribe: function() {
|
|
16
|
-
_this.observers = filter(_this.observers, function(other) {
|
|
15
|
+
unsubscribe: function () {
|
|
16
|
+
_this.observers = filter(_this.observers, function (other) {
|
|
17
17
|
return f !== other
|
|
18
18
|
})
|
|
19
19
|
if (!_this.observers.length && _this.onLastUnsubscribe) {
|
|
20
20
|
_this.onLastUnsubscribe()
|
|
21
21
|
}
|
|
22
|
-
}
|
|
22
|
+
}
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
notify: function (data) {
|
|
@@ -32,12 +32,14 @@ export var Observable = _Observable
|
|
|
32
32
|
|
|
33
33
|
export function mergeObservables() {
|
|
34
34
|
var observables = [].slice.call(arguments)
|
|
35
|
-
var globalObservable = new Observable(function(){
|
|
36
|
-
var subscriptions = map(observables, function(observable) {
|
|
37
|
-
|
|
35
|
+
var globalObservable = new Observable(function () {
|
|
36
|
+
var subscriptions = map(observables, function (observable) {
|
|
37
|
+
return observable.subscribe(function (data) {
|
|
38
|
+
return globalObservable.notify(data)
|
|
39
|
+
})
|
|
38
40
|
})
|
|
39
|
-
return function() {
|
|
40
|
-
return each(subscriptions, function(subscription) {
|
|
41
|
+
return function () {
|
|
42
|
+
return each(subscriptions, function (subscription) {
|
|
41
43
|
return subscription.unsubscribe()
|
|
42
44
|
})
|
|
43
45
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { noop, each } from './tools'
|
|
2
|
-
|
|
2
|
+
import { monitor } from './monitor'
|
|
3
3
|
/**
|
|
4
4
|
* Read bytes from a ReadableStream until at least `limit` bytes have been read (or until the end of
|
|
5
5
|
* the stream). The callback is invoked with the at most `limit` bytes, and indicates that the limit
|
|
@@ -14,7 +14,7 @@ export function readBytesFromStream(stream, callback, options) {
|
|
|
14
14
|
|
|
15
15
|
function readMore() {
|
|
16
16
|
reader.read().then(
|
|
17
|
-
function (result) {
|
|
17
|
+
monitor(function (result) {
|
|
18
18
|
if (result.done) {
|
|
19
19
|
onDone()
|
|
20
20
|
return
|
|
@@ -30,10 +30,10 @@ export function readBytesFromStream(stream, callback, options) {
|
|
|
30
30
|
} else {
|
|
31
31
|
readMore()
|
|
32
32
|
}
|
|
33
|
-
},
|
|
34
|
-
function (error) {
|
|
33
|
+
}),
|
|
34
|
+
monitor(function (error) {
|
|
35
35
|
callback(error)
|
|
36
|
-
}
|
|
36
|
+
})
|
|
37
37
|
)
|
|
38
38
|
}
|
|
39
39
|
|
package/src/helper/timer.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getZoneJsOriginalValue } from './getZoneJsOriginalValue'
|
|
2
2
|
import { getGlobalObject } from '../init'
|
|
3
|
-
|
|
3
|
+
import { monitor } from './monitor'
|
|
4
4
|
export function setTimeout(callback, delay) {
|
|
5
5
|
return getZoneJsOriginalValue(getGlobalObject(), 'setTimeout')(
|
|
6
|
-
callback,
|
|
6
|
+
monitor(callback),
|
|
7
7
|
delay
|
|
8
8
|
)
|
|
9
9
|
}
|
|
@@ -13,7 +13,7 @@ export function clearTimeout(timeoutId) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function setInterval(callback, delay) {
|
|
16
|
-
return getZoneJsOriginalValue(window, 'setInterval')(callback, delay)
|
|
16
|
+
return getZoneJsOriginalValue(window, 'setInterval')(monitor(callback), delay)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export function clearInterval(timeoutId) {
|
package/src/helper/tools.js
CHANGED
|
@@ -232,6 +232,7 @@ export var matchList = function (list, value, useStartsWith) {
|
|
|
232
232
|
}
|
|
233
233
|
// https://github.com/jquery/jquery/blob/a684e6ba836f7c553968d7d026ed7941e1a612d8/src/selector/escapeSelector.js
|
|
234
234
|
export var cssEscape = function (str) {
|
|
235
|
+
str = str + ''
|
|
235
236
|
if (window.CSS && window.CSS.escape) {
|
|
236
237
|
return window.CSS.escape(str)
|
|
237
238
|
}
|
|
@@ -1649,23 +1650,6 @@ export function isNullUndefinedDefaultValue(data, defaultValue) {
|
|
|
1649
1650
|
}
|
|
1650
1651
|
}
|
|
1651
1652
|
|
|
1652
|
-
export function requestIdleCallback(callback, opts) {
|
|
1653
|
-
// Use 'requestIdleCallback' when available: it will throttle the mutation processing if the
|
|
1654
|
-
// browser is busy rendering frames (ex: when frames are below 60fps). When not available, the
|
|
1655
|
-
// fallback on 'requestAnimationFrame' will still ensure the mutations are processed after any
|
|
1656
|
-
// browser rendering process (Layout, Recalculate Style, etc.), so we can serialize DOM nodes
|
|
1657
|
-
// efficiently.
|
|
1658
|
-
if (window.requestIdleCallback) {
|
|
1659
|
-
var id = window.requestIdleCallback(callback, opts)
|
|
1660
|
-
return function () {
|
|
1661
|
-
return window.cancelIdleCallback(id)
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
var id = window.requestAnimationFrame(callback)
|
|
1665
|
-
return function () {
|
|
1666
|
-
return window.cancelAnimationFrame(id)
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
1653
|
export function objectHasValue(object, value) {
|
|
1670
1654
|
return some(keys(object), function (key) {
|
|
1671
1655
|
return object[key] === value
|
package/src/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * from './error/trackRuntimeError'
|
|
|
9
9
|
export * from './console/consoleObservable'
|
|
10
10
|
export * from './report/reportObservable'
|
|
11
11
|
export * from './helper/display'
|
|
12
|
+
export * from './helper/monitor'
|
|
12
13
|
export * from './helper/sanitize'
|
|
13
14
|
export * from './helper/eventEmitter'
|
|
14
15
|
export * from './helper/lifeCycle'
|
package/src/init.js
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
callback()
|
|
6
|
-
}
|
|
7
|
-
})
|
|
8
|
-
return global
|
|
9
|
-
}
|
|
1
|
+
import { each, assign } from './helper/tools'
|
|
2
|
+
import { setDebugMode } from './helper/monitor'
|
|
3
|
+
import { catchUserErrors } from './helper/catchUserErrors'
|
|
4
|
+
|
|
10
5
|
export function makePublicApi(stub) {
|
|
11
|
-
var publicApi =
|
|
12
|
-
|
|
13
|
-
callback
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
var publicApi = assign(
|
|
7
|
+
{
|
|
8
|
+
onReady: function (callback) {
|
|
9
|
+
callback()
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
stub
|
|
13
|
+
)
|
|
16
14
|
|
|
17
15
|
// Add an "hidden" property to set debug mode. We define it that way to hide it
|
|
18
16
|
// as much as possible but of course it's not a real protection.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
Object.defineProperty(publicApi, '_setDebug', {
|
|
18
|
+
get: function () {
|
|
19
|
+
return setDebugMode
|
|
20
|
+
},
|
|
21
|
+
enumerable: false
|
|
22
|
+
})
|
|
25
23
|
|
|
26
24
|
return publicApi
|
|
27
25
|
}
|
|
@@ -30,7 +28,7 @@ export function defineGlobal(global, name, api) {
|
|
|
30
28
|
global[name] = api
|
|
31
29
|
if (existingGlobalVariable && existingGlobalVariable.q) {
|
|
32
30
|
each(existingGlobalVariable.q, function (fn) {
|
|
33
|
-
fn()
|
|
31
|
+
catchUserErrors(fn, 'onReady callback threw an error:')()
|
|
34
32
|
})
|
|
35
33
|
}
|
|
36
34
|
}
|
|
@@ -3,6 +3,7 @@ import { mergeObservables, Observable } from '../helper/observable'
|
|
|
3
3
|
import { includes, safeTruncate, filter, each } from '../helper/tools'
|
|
4
4
|
import { addEventListener } from '../browser/addEventListener'
|
|
5
5
|
import { DOM_EVENT } from '../helper/enums'
|
|
6
|
+
import { monitor } from '../helper/monitor'
|
|
6
7
|
export var RawReportType = {
|
|
7
8
|
intervention: 'intervention',
|
|
8
9
|
deprecation: 'deprecation',
|
|
@@ -30,11 +31,11 @@ function createReportObservable(reportTypes) {
|
|
|
30
31
|
return
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
var handleReports = function (reports) {
|
|
34
|
+
var handleReports = monitor(function (reports) {
|
|
34
35
|
each(reports, function (report) {
|
|
35
36
|
observable.notify(buildRawReportFromReport(report))
|
|
36
37
|
})
|
|
37
|
-
}
|
|
38
|
+
})
|
|
38
39
|
|
|
39
40
|
var observer = new window.ReportingObserver(handleReports, {
|
|
40
41
|
types: reportTypes,
|
package/src/transport/batch.js
CHANGED
|
@@ -76,13 +76,13 @@ export var processedMessageByDataMap = function (message) {
|
|
|
76
76
|
}
|
|
77
77
|
})
|
|
78
78
|
if (
|
|
79
|
-
message.
|
|
80
|
-
isObject(message.
|
|
81
|
-
!isEmptyObject(message.
|
|
79
|
+
message.context &&
|
|
80
|
+
isObject(message.context) &&
|
|
81
|
+
!isEmptyObject(message.context)
|
|
82
82
|
) {
|
|
83
83
|
// 自定义tag, 存储成field
|
|
84
84
|
var _tagKeys = []
|
|
85
|
-
each(message.
|
|
85
|
+
each(message.context, function (_value, _key) {
|
|
86
86
|
// 如果和之前tag重名,则舍弃
|
|
87
87
|
if (filterFileds.indexOf(_key) > -1) return
|
|
88
88
|
filterFileds.push(_key)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { newRetryState, sendWithRetryStrategy } from './sendWithRetryStrategy'
|
|
2
2
|
import { addEventListener } from '../browser/addEventListener'
|
|
3
|
+
import { monitor } from '../helper/monitor'
|
|
3
4
|
/**
|
|
4
5
|
* Use POST request without content type to:
|
|
5
6
|
* - avoid CORS preflight requests
|
|
@@ -74,15 +75,15 @@ export function fetchKeepAliveStrategy(
|
|
|
74
75
|
keepalive: true,
|
|
75
76
|
mode: 'cors'
|
|
76
77
|
}).then(
|
|
77
|
-
function (response) {
|
|
78
|
+
monitor(function (response) {
|
|
78
79
|
if (typeof onResponse === 'function') {
|
|
79
80
|
onResponse({ status: response.status, type: response.type })
|
|
80
81
|
}
|
|
81
|
-
},
|
|
82
|
-
function () {
|
|
82
|
+
}),
|
|
83
|
+
monitor(function () {
|
|
83
84
|
// failed to queue the request
|
|
84
85
|
sendXHR(url, data, onResponse)
|
|
85
|
-
}
|
|
86
|
+
})
|
|
86
87
|
)
|
|
87
88
|
} else {
|
|
88
89
|
sendXHR(url, data, onResponse)
|