@cloudcare/browser-core 3.0.22 → 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.
Files changed (47) hide show
  1. package/cjs/browser/addEventListener.js +9 -7
  2. package/cjs/browser/fetchObservable.js +5 -3
  3. package/cjs/console/consoleObservable.js +5 -1
  4. package/cjs/dataMap.js +5 -1
  5. package/cjs/helper/errorTools.js +7 -3
  6. package/cjs/helper/instrumentMethod.js +4 -2
  7. package/cjs/helper/monitor.js +59 -0
  8. package/cjs/helper/readBytesFromStream.js +5 -3
  9. package/cjs/helper/timer.js +4 -2
  10. package/cjs/helper/tools.js +2 -20
  11. package/cjs/index.js +13 -0
  12. package/cjs/init.js +13 -19
  13. package/cjs/report/reportObservable.js +4 -3
  14. package/cjs/transport/batch.js +2 -2
  15. package/cjs/transport/httpRequest.js +5 -3
  16. package/esm/browser/addEventListener.js +8 -7
  17. package/esm/browser/fetchObservable.js +4 -3
  18. package/esm/console/consoleObservable.js +4 -1
  19. package/esm/dataMap.js +5 -1
  20. package/esm/helper/errorTools.js +6 -3
  21. package/esm/helper/instrumentMethod.js +3 -2
  22. package/esm/helper/monitor.js +40 -0
  23. package/esm/helper/readBytesFromStream.js +4 -3
  24. package/esm/helper/timer.js +3 -2
  25. package/esm/helper/tools.js +2 -18
  26. package/esm/index.js +1 -0
  27. package/esm/init.js +12 -18
  28. package/esm/report/reportObservable.js +3 -3
  29. package/esm/transport/batch.js +2 -2
  30. package/esm/transport/httpRequest.js +4 -3
  31. package/package.json +2 -2
  32. package/src/browser/addEventListener.js +8 -7
  33. package/src/browser/fetchObservable.js +12 -3
  34. package/src/console/consoleObservable.js +4 -2
  35. package/src/dataMap.js +6 -1
  36. package/src/helper/errorTools.js +6 -5
  37. package/src/helper/instrumentMethod.js +5 -2
  38. package/src/helper/monitor.js +44 -0
  39. package/src/helper/observable.js +10 -8
  40. package/src/helper/readBytesFromStream.js +5 -5
  41. package/src/helper/timer.js +3 -3
  42. package/src/helper/tools.js +1 -17
  43. package/src/index.js +1 -0
  44. package/src/init.js +19 -21
  45. package/src/report/reportObservable.js +3 -2
  46. package/src/transport/batch.js +4 -4
  47. package/src/transport/httpRequest.js +5 -4
@@ -0,0 +1,40 @@
1
+ import { ConsoleApiName, display } from './display';
2
+ var onMonitorErrorCollected;
3
+ var debugMode = false;
4
+ export function startMonitorErrorCollection(newOnMonitorErrorCollected) {
5
+ onMonitorErrorCollected = newOnMonitorErrorCollected;
6
+ }
7
+ export function setDebugMode(newDebugMode) {
8
+ debugMode = newDebugMode;
9
+ }
10
+ export function resetMonitor() {
11
+ onMonitorErrorCollected = undefined;
12
+ debugMode = false;
13
+ }
14
+ export function monitor(fn) {
15
+ return function () {
16
+ return callMonitored(fn, this, arguments);
17
+ };
18
+ }
19
+ export function callMonitored(fn, context, args) {
20
+ try {
21
+ return fn.apply(context, args);
22
+ } catch (e) {
23
+ displayIfDebugEnabled(ConsoleApiName.error, e);
24
+
25
+ if (onMonitorErrorCollected) {
26
+ try {
27
+ onMonitorErrorCollected(e);
28
+ } catch (e) {
29
+ displayIfDebugEnabled(ConsoleApiName.error, e);
30
+ }
31
+ }
32
+ }
33
+ }
34
+ export function displayIfDebugEnabled(api) {
35
+ var args = [].slice.call(arguments, 1);
36
+
37
+ if (debugMode) {
38
+ display.apply(null, [api, '[MONITOR]'].concat(args));
39
+ }
40
+ }
@@ -1,4 +1,5 @@
1
1
  import { noop, each } from './tools';
2
+ import { monitor } from './monitor';
2
3
  /**
3
4
  * Read bytes from a ReadableStream until at least `limit` bytes have been read (or until the end of
4
5
  * the stream). The callback is invoked with the at most `limit` bytes, and indicates that the limit
@@ -12,7 +13,7 @@ export function readBytesFromStream(stream, callback, options) {
12
13
  readMore();
13
14
 
14
15
  function readMore() {
15
- reader.read().then(function (result) {
16
+ reader.read().then(monitor(function (result) {
16
17
  if (result.done) {
17
18
  onDone();
18
19
  return;
@@ -29,9 +30,9 @@ export function readBytesFromStream(stream, callback, options) {
29
30
  } else {
30
31
  readMore();
31
32
  }
32
- }, function (error) {
33
+ }), monitor(function (error) {
33
34
  callback(error);
34
- });
35
+ }));
35
36
  }
36
37
 
37
38
  function onDone() {
@@ -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);
@@ -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 { extend, each } from './helper/tools';
4
- export function makeGlobal(stub) {
5
- var global = extend({}, stub, {
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 = extend({}, stub, {
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 handleReports(reports) {
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
@@ -66,10 +66,10 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
66
66
  }
67
67
  });
68
68
 
69
- if (message.tags && isObject(message.tags) && !isEmptyObject(message.tags)) {
69
+ if (message.context && isObject(message.context) && !isEmptyObject(message.context)) {
70
70
  // 自定义tag, 存储成field
71
71
  var _tagKeys = [];
72
- each(message.tags, function (_value, _key) {
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.22",
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": "c42f3cdce8c9f1af6ac6bec06c7a7e83a9638467"
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, events, listener, options) {
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(events, function (event) {
39
- add.call(eventTarget, event, wrappedListener, options)
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(events, function (event) {
44
- remove.call(eventTarget, event, wrappedListener, options)
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(observable, input, init)
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(observable, responsePromise, context)
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
- observable.notify(buildConsoleLog(params, api, handlingStack))
33
+ callMonitored(function () {
34
+ observable.notify(buildConsoleLog(params, api, handlingStack))
35
+ })
34
36
  }
35
37
  return function () {
36
38
  console[api] = originalConsoleApi
package/src/dataMap.js CHANGED
@@ -54,6 +54,8 @@ export var dataMap = {
54
54
  view_action_count: 'view.action.count',
55
55
  first_contentful_paint: 'view.first_contentful_paint',
56
56
  largest_contentful_paint: 'view.largest_contentful_paint',
57
+ largest_contentful_paint_element_selector:
58
+ 'view.largest_contentful_paint_element_selector',
57
59
  cumulative_layout_shift: 'view.cumulative_layout_shift',
58
60
  first_input_delay: 'view.first_input_delay',
59
61
  loading_time: 'view.loading_time',
@@ -70,7 +72,8 @@ export var dataMap = {
70
72
  time_spent: 'view.time_spent',
71
73
  first_byte: 'view.first_byte',
72
74
  in_foreground_periods: 'view.in_foreground_periods',
73
- frustration_count: 'view.frustration.count'
75
+ frustration_count: 'view.frustration.count',
76
+ custom_timings: 'view.custom_timings'
74
77
  }
75
78
  },
76
79
  resource: {
@@ -91,6 +94,8 @@ export var dataMap = {
91
94
  fields: {
92
95
  duration: 'resource.duration',
93
96
  resource_size: 'resource.size',
97
+ resource_encode_size: 'resource.encode_size',
98
+ resource_render_blocking_status: 'resource.render_blocking_status',
94
99
  resource_dns: 'resource.dns',
95
100
  resource_tcp: 'resource.tcp',
96
101
  resource_ssl: 'resource.ssl',
@@ -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
- var stackTrace = computeStackTrace(error)
102
- stackTrace.stack = stackTrace.stack.slice(internalFramesToSkip)
103
- formattedStack = toStackTraceString(stackTrace)
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.apply(this, arguments)
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.apply(this, arguments)
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
+ }
@@ -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
- return observable.subscribe(function(data) { return globalObservable.notify(data) })
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
 
@@ -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) {
@@ -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'