@cloudcare/browser-core 3.1.23 → 3.2.0
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/pageExitObservable.js +1 -1
- package/cjs/browser/pageExitObservable.js.map +1 -1
- package/cjs/browser/runOnReadyState.js +5 -1
- package/cjs/browser/runOnReadyState.js.map +1 -1
- package/cjs/console/consoleObservable.js +17 -9
- package/cjs/console/consoleObservable.js.map +1 -1
- package/cjs/dataMap.js +11 -2
- package/cjs/dataMap.js.map +1 -1
- package/cjs/helper/boundedBuffer.js +21 -17
- package/cjs/helper/boundedBuffer.js.map +1 -1
- package/cjs/helper/connectivity.js +16 -0
- package/cjs/helper/connectivity.js.map +1 -0
- package/cjs/helper/display.js +15 -12
- package/cjs/helper/display.js.map +1 -1
- package/cjs/helper/displayAlreadyInitializedError.js +13 -0
- package/cjs/helper/displayAlreadyInitializedError.js.map +1 -0
- package/cjs/helper/encoder.js +43 -0
- package/cjs/helper/encoder.js.map +1 -0
- package/cjs/helper/lifeCycle.js +0 -1
- package/cjs/helper/lifeCycle.js.map +1 -1
- package/cjs/helper/monitor.js +6 -6
- package/cjs/helper/monitor.js.map +1 -1
- package/cjs/helper/serialisation/jsonStringify.js.map +1 -1
- package/cjs/index.js +33 -0
- package/cjs/index.js.map +1 -1
- package/cjs/report/reportObservable.js +26 -20
- package/cjs/report/reportObservable.js.map +1 -1
- package/cjs/telemetry/telemetry.js +60 -31
- package/cjs/telemetry/telemetry.js.map +1 -1
- package/cjs/telemetry/types.js +2 -1
- package/cjs/telemetry/types.js.map +1 -1
- package/cjs/transport/batch.js +129 -79
- package/cjs/transport/batch.js.map +1 -1
- package/cjs/transport/flushController.js +18 -5
- package/cjs/transport/flushController.js.map +1 -1
- package/cjs/transport/httpRequest.js +35 -22
- package/cjs/transport/httpRequest.js.map +1 -1
- package/cjs/transport/index.js +4 -4
- package/cjs/transport/index.js.map +1 -1
- package/cjs/transport/startBatchWithReplica.js +26 -10
- package/cjs/transport/startBatchWithReplica.js.map +1 -1
- package/esm/browser/pageExitObservable.js +1 -1
- package/esm/browser/pageExitObservable.js.map +1 -1
- package/esm/browser/runOnReadyState.js +5 -1
- package/esm/browser/runOnReadyState.js.map +1 -1
- package/esm/console/consoleObservable.js +18 -10
- package/esm/console/consoleObservable.js.map +1 -1
- package/esm/dataMap.js +11 -2
- package/esm/dataMap.js.map +1 -1
- package/esm/helper/boundedBuffer.js +21 -16
- package/esm/helper/boundedBuffer.js.map +1 -1
- package/esm/helper/connectivity.js +10 -0
- package/esm/helper/connectivity.js.map +1 -0
- package/esm/helper/display.js +12 -11
- package/esm/helper/display.js.map +1 -1
- package/esm/helper/displayAlreadyInitializedError.js +7 -0
- package/esm/helper/displayAlreadyInitializedError.js.map +1 -0
- package/esm/helper/encoder.js +37 -0
- package/esm/helper/encoder.js.map +1 -0
- package/esm/helper/lifeCycle.js +0 -1
- package/esm/helper/lifeCycle.js.map +1 -1
- package/esm/helper/monitor.js +6 -6
- package/esm/helper/monitor.js.map +1 -1
- package/esm/helper/serialisation/jsonStringify.js.map +1 -1
- package/esm/index.js +3 -0
- package/esm/index.js.map +1 -1
- package/esm/report/reportObservable.js +27 -21
- package/esm/report/reportObservable.js.map +1 -1
- package/esm/telemetry/telemetry.js +57 -31
- package/esm/telemetry/telemetry.js.map +1 -1
- package/esm/telemetry/types.js +2 -1
- package/esm/telemetry/types.js.map +1 -1
- package/esm/transport/batch.js +127 -77
- package/esm/transport/batch.js.map +1 -1
- package/esm/transport/flushController.js +18 -5
- package/esm/transport/flushController.js.map +1 -1
- package/esm/transport/httpRequest.js +35 -22
- package/esm/transport/httpRequest.js.map +1 -1
- package/esm/transport/index.js +1 -1
- package/esm/transport/index.js.map +1 -1
- package/esm/transport/startBatchWithReplica.js +27 -11
- package/esm/transport/startBatchWithReplica.js.map +1 -1
- package/package.json +2 -2
- package/src/browser/pageExitObservable.js +2 -2
- package/src/browser/runOnReadyState.js +3 -1
- package/src/console/consoleObservable.js +22 -14
- package/src/dataMap.js +11 -2
- package/src/helper/boundedBuffer.js +21 -14
- package/src/helper/connectivity.js +11 -0
- package/src/helper/display.js +16 -14
- package/src/helper/displayAlreadyInitializedError.js +7 -0
- package/src/helper/encoder.js +43 -0
- package/src/helper/lifeCycle.js +0 -1
- package/src/helper/monitor.js +6 -6
- package/src/helper/serialisation/jsonStringify.js +1 -1
- package/src/index.js +3 -0
- package/src/report/reportObservable.js +43 -27
- package/src/telemetry/telemetry.js +60 -37
- package/src/telemetry/types.js +2 -1
- package/src/transport/batch.js +154 -89
- package/src/transport/flushController.js +19 -6
- package/src/transport/httpRequest.js +34 -35
- package/src/transport/index.js +1 -1
- package/src/transport/startBatchWithReplica.js +25 -14
- package/types/index.d.ts +12 -0
|
@@ -1,20 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createBatch } from './batch';
|
|
2
2
|
import { createHttpRequest } from './httpRequest';
|
|
3
3
|
import { createFlushController } from './flushController';
|
|
4
|
-
export function startBatchWithReplica(configuration,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
export function startBatchWithReplica(configuration, primary, reportError, pageExitObservable, sessionExpireObservable, batchFactoryImp) {
|
|
5
|
+
if (batchFactoryImp === undefined) {
|
|
6
|
+
batchFactoryImp = createBatch;
|
|
7
|
+
}
|
|
8
|
+
var primaryBatch = createBatchFromConfig(configuration, primary);
|
|
9
|
+
function createBatchFromConfig(configuration, batchConfiguration) {
|
|
10
|
+
return batchFactoryImp({
|
|
11
|
+
encoder: batchConfiguration.encoder,
|
|
12
|
+
request: createHttpRequest(batchConfiguration.endpoint, configuration.batchBytesLimit, reportError),
|
|
13
|
+
flushController: createFlushController({
|
|
14
|
+
messagesLimit: configuration.batchMessagesLimit,
|
|
15
|
+
bytesLimit: configuration.batchBytesLimit,
|
|
16
|
+
durationLimit: configuration.flushTimeout,
|
|
17
|
+
pageExitObservable: pageExitObservable,
|
|
18
|
+
sessionExpireObservable: sessionExpireObservable
|
|
19
|
+
}),
|
|
20
|
+
messageBytesLimit: configuration.messageBytesLimit,
|
|
21
|
+
sendContentTypeByJson: configuration.sendContentTypeByJson
|
|
22
|
+
});
|
|
14
23
|
}
|
|
15
24
|
return {
|
|
25
|
+
flushObservable: primaryBatch.flushController.flushObservable,
|
|
16
26
|
add: function add(message) {
|
|
17
27
|
primaryBatch.add(message);
|
|
28
|
+
},
|
|
29
|
+
upsert: function upsert(message, key) {
|
|
30
|
+
primaryBatch.upsert(message, key);
|
|
31
|
+
},
|
|
32
|
+
stop: function stop() {
|
|
33
|
+
primaryBatch.stop();
|
|
18
34
|
}
|
|
19
35
|
};
|
|
20
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startBatchWithReplica.js","names":["
|
|
1
|
+
{"version":3,"file":"startBatchWithReplica.js","names":["createBatch","createHttpRequest","createFlushController","startBatchWithReplica","configuration","primary","reportError","pageExitObservable","sessionExpireObservable","batchFactoryImp","undefined","primaryBatch","createBatchFromConfig","batchConfiguration","encoder","request","endpoint","batchBytesLimit","flushController","messagesLimit","batchMessagesLimit","bytesLimit","durationLimit","flushTimeout","messageBytesLimit","sendContentTypeByJson","flushObservable","add","message","upsert","key","stop"],"sources":["../../src/transport/startBatchWithReplica.js"],"sourcesContent":["import { createBatch } from './batch'\nimport { createHttpRequest } from './httpRequest'\nimport { createFlushController } from './flushController'\nexport function startBatchWithReplica(\n configuration,\n primary,\n reportError,\n pageExitObservable,\n sessionExpireObservable,\n batchFactoryImp\n) {\n if (batchFactoryImp === undefined) {\n batchFactoryImp = createBatch\n }\n var primaryBatch = createBatchFromConfig(configuration, primary)\n\n function createBatchFromConfig(configuration, batchConfiguration) {\n return batchFactoryImp({\n encoder: batchConfiguration.encoder,\n request: createHttpRequest(\n batchConfiguration.endpoint,\n configuration.batchBytesLimit,\n reportError\n ),\n flushController: createFlushController({\n messagesLimit: configuration.batchMessagesLimit,\n bytesLimit: configuration.batchBytesLimit,\n durationLimit: configuration.flushTimeout,\n pageExitObservable: pageExitObservable,\n sessionExpireObservable: sessionExpireObservable\n }),\n messageBytesLimit: configuration.messageBytesLimit,\n sendContentTypeByJson: configuration.sendContentTypeByJson\n })\n }\n return {\n flushObservable: primaryBatch.flushController.flushObservable,\n add: function (message) {\n primaryBatch.add(message)\n },\n upsert: function (message, key) {\n primaryBatch.upsert(message, key)\n },\n\n stop: function () {\n primaryBatch.stop()\n }\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,SAAS;AACrC,SAASC,iBAAiB,QAAQ,eAAe;AACjD,SAASC,qBAAqB,QAAQ,mBAAmB;AACzD,OAAO,SAASC,qBAAqBA,CACnCC,aAAa,EACbC,OAAO,EACPC,WAAW,EACXC,kBAAkB,EAClBC,uBAAuB,EACvBC,eAAe,EACf;EACA,IAAIA,eAAe,KAAKC,SAAS,EAAE;IACjCD,eAAe,GAAGT,WAAW;EAC/B;EACA,IAAIW,YAAY,GAAGC,qBAAqB,CAACR,aAAa,EAAEC,OAAO,CAAC;EAEhE,SAASO,qBAAqBA,CAACR,aAAa,EAAES,kBAAkB,EAAE;IAChE,OAAOJ,eAAe,CAAC;MACrBK,OAAO,EAAED,kBAAkB,CAACC,OAAO;MACnCC,OAAO,EAAEd,iBAAiB,CACxBY,kBAAkB,CAACG,QAAQ,EAC3BZ,aAAa,CAACa,eAAe,EAC7BX,WACF,CAAC;MACDY,eAAe,EAAEhB,qBAAqB,CAAC;QACrCiB,aAAa,EAAEf,aAAa,CAACgB,kBAAkB;QAC/CC,UAAU,EAAEjB,aAAa,CAACa,eAAe;QACzCK,aAAa,EAAElB,aAAa,CAACmB,YAAY;QACzChB,kBAAkB,EAAEA,kBAAkB;QACtCC,uBAAuB,EAAEA;MAC3B,CAAC,CAAC;MACFgB,iBAAiB,EAAEpB,aAAa,CAACoB,iBAAiB;MAClDC,qBAAqB,EAAErB,aAAa,CAACqB;IACvC,CAAC,CAAC;EACJ;EACA,OAAO;IACLC,eAAe,EAAEf,YAAY,CAACO,eAAe,CAACQ,eAAe;IAC7DC,GAAG,EAAE,SAAAA,IAAUC,OAAO,EAAE;MACtBjB,YAAY,CAACgB,GAAG,CAACC,OAAO,CAAC;IAC3B,CAAC;IACDC,MAAM,EAAE,SAAAA,OAAUD,OAAO,EAAEE,GAAG,EAAE;MAC9BnB,YAAY,CAACkB,MAAM,CAACD,OAAO,EAAEE,GAAG,CAAC;IACnC,CAAC;IAEDC,IAAI,EAAE,SAAAA,KAAA,EAAY;MAChBpB,YAAY,CAACoB,IAAI,CAAC,CAAC;IACrB;EACF,CAAC;AACH","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcare/browser-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"author": "dataflux",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"description": "DataFlux RUM Web 端数据指标监控",
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "81a7f878553edc3a3fe9eb57779cad505c55d4de"
|
|
26
26
|
}
|
|
@@ -19,8 +19,8 @@ export function createPageExitObservable() {
|
|
|
19
19
|
* (e.g. when user switches to a different application, goes to homescreen, etc), or is being unloaded.
|
|
20
20
|
*/
|
|
21
21
|
var visibilityChangeListener = addEventListeners(
|
|
22
|
-
|
|
23
|
-
[DOM_EVENT.VISIBILITY_CHANGE, DOM_EVENT.FREEZE
|
|
22
|
+
window,
|
|
23
|
+
[DOM_EVENT.VISIBILITY_CHANGE, DOM_EVENT.FREEZE],
|
|
24
24
|
function (event) {
|
|
25
25
|
if (
|
|
26
26
|
event.type === DOM_EVENT.VISIBILITY_CHANGE &&
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { addEventListener } from './addEventListener'
|
|
2
2
|
import { DOM_EVENT } from '../helper/enums'
|
|
3
|
+
import { noop } from '../helper/tools'
|
|
3
4
|
export function runOnReadyState(expectedReadyState, callback) {
|
|
4
5
|
if (
|
|
5
6
|
document.readyState === expectedReadyState ||
|
|
6
7
|
document.readyState === 'complete'
|
|
7
8
|
) {
|
|
8
9
|
callback()
|
|
10
|
+
return { stop: noop }
|
|
9
11
|
} else {
|
|
10
12
|
var eventName =
|
|
11
13
|
expectedReadyState === 'complete'
|
|
12
14
|
? DOM_EVENT.LOAD
|
|
13
15
|
: DOM_EVENT.DOM_CONTENT_LOADED
|
|
14
|
-
addEventListener(window, eventName, callback, { once: true })
|
|
16
|
+
return addEventListener(window, eventName, callback, { once: true })
|
|
15
17
|
}
|
|
16
18
|
}
|
|
@@ -6,10 +6,12 @@ import {
|
|
|
6
6
|
flattenErrorCauses
|
|
7
7
|
} from '../helper/errorTools'
|
|
8
8
|
import { mergeObservables, Observable } from '../helper/observable'
|
|
9
|
-
import { find, map } from '../helper/tools'
|
|
9
|
+
import { find, map, clocksNow } from '../helper/tools'
|
|
10
10
|
import { jsonStringify } from '../helper/serialisation/jsonStringify'
|
|
11
11
|
import { ConsoleApiName } from '../helper/display'
|
|
12
12
|
import { callMonitored } from '../helper/monitor'
|
|
13
|
+
import { ErrorHandling } from '../helper/enums'
|
|
14
|
+
import { ErrorSource } from '../helper/errorTools'
|
|
13
15
|
var consoleObservablesByApi = {}
|
|
14
16
|
|
|
15
17
|
export function initConsoleObservable(apis) {
|
|
@@ -22,7 +24,9 @@ export function initConsoleObservable(apis) {
|
|
|
22
24
|
|
|
23
25
|
return mergeObservables.apply(this, consoleObservables)
|
|
24
26
|
}
|
|
25
|
-
|
|
27
|
+
export function resetConsoleObservable() {
|
|
28
|
+
consoleObservablesByApi = {}
|
|
29
|
+
}
|
|
26
30
|
/* eslint-disable no-console */
|
|
27
31
|
function createConsoleObservable(api) {
|
|
28
32
|
return new Observable(function (observable) {
|
|
@@ -45,27 +49,31 @@ function buildConsoleLog(params, api, handlingStack) {
|
|
|
45
49
|
var message = map(params, function (param) {
|
|
46
50
|
return formatConsoleParameters(param)
|
|
47
51
|
}).join(' ')
|
|
48
|
-
var
|
|
49
|
-
var causes
|
|
52
|
+
var error
|
|
50
53
|
if (api === ConsoleApiName.error) {
|
|
51
54
|
var firstErrorParam = find(params, function (param) {
|
|
52
55
|
return param instanceof Error
|
|
53
56
|
})
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
error = {
|
|
58
|
+
stack: firstErrorParam
|
|
59
|
+
? toStackTraceString(computeStackTrace(firstErrorParam))
|
|
60
|
+
: undefined,
|
|
61
|
+
causes: firstErrorParam
|
|
62
|
+
? flattenErrorCauses(firstErrorParam, 'console')
|
|
63
|
+
: undefined,
|
|
64
|
+
startClocks: clocksNow(),
|
|
65
|
+
message: message,
|
|
66
|
+
source: ErrorSource.CONSOLE,
|
|
67
|
+
handling: ErrorHandling.HANDLED,
|
|
68
|
+
handlingStack: handlingStack
|
|
69
|
+
}
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
return {
|
|
64
73
|
api: api,
|
|
65
74
|
message: message,
|
|
66
|
-
|
|
67
|
-
handlingStack: handlingStack
|
|
68
|
-
causes: causes
|
|
75
|
+
error: error,
|
|
76
|
+
handlingStack: handlingStack
|
|
69
77
|
}
|
|
70
78
|
}
|
|
71
79
|
|
package/src/dataMap.js
CHANGED
|
@@ -97,6 +97,7 @@ export var dataMap = {
|
|
|
97
97
|
tags: {
|
|
98
98
|
trace_id: '_gc.trace_id',
|
|
99
99
|
span_id: '_gc.span_id',
|
|
100
|
+
resource_id: 'resource.id',
|
|
100
101
|
resource_url: 'resource.url',
|
|
101
102
|
resource_url_host: 'resource.url_host',
|
|
102
103
|
resource_url_path: 'resource.url_path',
|
|
@@ -159,7 +160,13 @@ export var dataMap = {
|
|
|
159
160
|
long_task_id: 'long_task.id'
|
|
160
161
|
},
|
|
161
162
|
fields: {
|
|
162
|
-
duration: 'long_task.duration'
|
|
163
|
+
duration: 'long_task.duration',
|
|
164
|
+
blocking_duration: 'long_task.blocking_duration',
|
|
165
|
+
first_ui_event_timestamp: 'long_task.first_ui_event_timestamp',
|
|
166
|
+
render_start: 'long_task.render_start',
|
|
167
|
+
style_and_layout_start: 'long_task.style_and_layout_start',
|
|
168
|
+
long_task_start_time: 'long_task.start_time',
|
|
169
|
+
scripts: ['string', 'long_task.scripts']
|
|
163
170
|
}
|
|
164
171
|
},
|
|
165
172
|
action: {
|
|
@@ -205,7 +212,9 @@ export var dataMap = {
|
|
|
205
212
|
status: 'status'
|
|
206
213
|
},
|
|
207
214
|
fields: {
|
|
208
|
-
message: ['string', 'message']
|
|
215
|
+
message: ['string', 'message'],
|
|
216
|
+
error_message: ['string', 'error.message'],
|
|
217
|
+
error_stack: ['string', 'error.stack']
|
|
209
218
|
}
|
|
210
219
|
}
|
|
211
220
|
}
|
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { removeItem } from './tools'
|
|
2
2
|
var BUFFER_LIMIT = 500
|
|
3
|
+
export function createBoundedBuffer() {
|
|
4
|
+
var buffer = []
|
|
3
5
|
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
_BoundedBuffer.prototype = {
|
|
8
|
-
add: function (callback) {
|
|
9
|
-
var length = this.buffer.push(callback)
|
|
6
|
+
var add = function (callback) {
|
|
7
|
+
var length = buffer.push(callback)
|
|
10
8
|
if (length > BUFFER_LIMIT) {
|
|
11
|
-
|
|
9
|
+
buffer.splice(0, 1)
|
|
12
10
|
}
|
|
13
|
-
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
var remove = function (callback) {
|
|
14
|
+
removeItem(buffer, callback)
|
|
15
|
+
}
|
|
14
16
|
|
|
15
|
-
drain
|
|
16
|
-
|
|
17
|
-
callback()
|
|
17
|
+
const drain = function (arg) {
|
|
18
|
+
buffer.forEach(function (callback) {
|
|
19
|
+
callback(arg)
|
|
18
20
|
})
|
|
19
|
-
|
|
21
|
+
buffer.length = 0
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
add: add,
|
|
26
|
+
remove: add,
|
|
27
|
+
drain: drain
|
|
20
28
|
}
|
|
21
29
|
}
|
|
22
|
-
export var BoundedBuffer = _BoundedBuffer
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function getConnectivity() {
|
|
2
|
+
var navigator = window.navigator
|
|
3
|
+
return {
|
|
4
|
+
status: navigator.onLine ? 'connected' : 'not_connected',
|
|
5
|
+
interfaces:
|
|
6
|
+
navigator.connection && navigator.connection.type
|
|
7
|
+
? [navigator.connection.type]
|
|
8
|
+
: undefined,
|
|
9
|
+
effective_type: navigator.connection?.effectiveType
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/helper/display.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
|
|
2
1
|
export var ConsoleApiName = {
|
|
3
2
|
log: 'log',
|
|
4
3
|
debug: 'debug',
|
|
5
4
|
info: 'info',
|
|
6
5
|
warn: 'warn',
|
|
7
|
-
error: 'error'
|
|
8
|
-
}
|
|
9
|
-
export var display = function(api) {
|
|
10
|
-
var args = [].slice.call(arguments, 1)
|
|
11
|
-
if (!Object.prototype.hasOwnProperty.call(ConsoleApiName, api)) {
|
|
12
|
-
api = ConsoleApiName.log
|
|
13
|
-
}
|
|
14
|
-
display[api].apply(display,args)
|
|
6
|
+
error: 'error'
|
|
15
7
|
}
|
|
8
|
+
export var globalConsole = console
|
|
9
|
+
|
|
10
|
+
export var originalConsoleMethods = {}
|
|
11
|
+
Object.keys(ConsoleApiName).forEach(function (name) {
|
|
12
|
+
originalConsoleMethods[name] = globalConsole[name]
|
|
13
|
+
})
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
display
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
var PREFIX = 'GUANCE Browser SDK:'
|
|
16
|
+
|
|
17
|
+
export var display = {
|
|
18
|
+
debug: originalConsoleMethods.debug.bind(globalConsole, PREFIX),
|
|
19
|
+
log: originalConsoleMethods.log.bind(globalConsole, PREFIX),
|
|
20
|
+
info: originalConsoleMethods.info.bind(globalConsole, PREFIX),
|
|
21
|
+
warn: originalConsoleMethods.warn.bind(globalConsole, PREFIX),
|
|
22
|
+
error: originalConsoleMethods.error.bind(globalConsole, PREFIX)
|
|
23
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { computeBytesCount } from './byteUtils'
|
|
2
|
+
|
|
3
|
+
export function createIdentityEncoder() {
|
|
4
|
+
var output = ''
|
|
5
|
+
var outputBytesCount = 0
|
|
6
|
+
|
|
7
|
+
return {
|
|
8
|
+
isAsync: false,
|
|
9
|
+
|
|
10
|
+
isEmpty: function () {
|
|
11
|
+
return !output
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
write: function (data, callback) {
|
|
15
|
+
var additionalEncodedBytesCount = computeBytesCount(data)
|
|
16
|
+
outputBytesCount += additionalEncodedBytesCount
|
|
17
|
+
output += data
|
|
18
|
+
if (callback) {
|
|
19
|
+
callback(additionalEncodedBytesCount)
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
finish: function (callback) {
|
|
24
|
+
callback(this.finishSync())
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
finishSync: function () {
|
|
28
|
+
var result = {
|
|
29
|
+
output: output,
|
|
30
|
+
outputBytesCount: outputBytesCount,
|
|
31
|
+
rawBytesCount: outputBytesCount,
|
|
32
|
+
pendingData: ''
|
|
33
|
+
}
|
|
34
|
+
output = ''
|
|
35
|
+
outputBytesCount = 0
|
|
36
|
+
return result
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
estimateEncodedBytesCount: function (data) {
|
|
40
|
+
return data.length
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/helper/lifeCycle.js
CHANGED
package/src/helper/monitor.js
CHANGED
|
@@ -25,21 +25,21 @@ export function callMonitored(fn, context, args) {
|
|
|
25
25
|
try {
|
|
26
26
|
return fn.apply(context, args)
|
|
27
27
|
} catch (e) {
|
|
28
|
-
displayIfDebugEnabled(
|
|
28
|
+
displayIfDebugEnabled(e)
|
|
29
29
|
if (onMonitorErrorCollected) {
|
|
30
30
|
try {
|
|
31
31
|
onMonitorErrorCollected(e)
|
|
32
32
|
} catch (e) {
|
|
33
|
-
displayIfDebugEnabled(
|
|
33
|
+
displayIfDebugEnabled(e)
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export function displayIfDebugEnabled(
|
|
40
|
-
var args = [].slice.call(arguments
|
|
41
|
-
// display.apply(null, [
|
|
39
|
+
export function displayIfDebugEnabled() {
|
|
40
|
+
var args = [].slice.call(arguments)
|
|
41
|
+
// display.error.apply(null, ['[MONITOR]'].concat(args))
|
|
42
42
|
if (debugMode) {
|
|
43
|
-
display.apply(null, [
|
|
43
|
+
display.error.apply(null, ['[MONITOR]'].concat(args))
|
|
44
44
|
}
|
|
45
45
|
}
|
package/src/index.js
CHANGED
|
@@ -48,7 +48,10 @@ export * from './helper/serialisation/heavyCustomerDataWarning'
|
|
|
48
48
|
export * from './helper/serialisation/jsonStringify'
|
|
49
49
|
export * from './helper/serialisation/rowData'
|
|
50
50
|
export * from './helper/serialisation/storedContextManager'
|
|
51
|
+
export * from './helper/encoder'
|
|
51
52
|
export * from './user'
|
|
52
53
|
export * from './helper/polyfills'
|
|
53
54
|
export * from './telemetry/telemetry'
|
|
54
55
|
export * from './helper/catchUserErrors'
|
|
56
|
+
export * from './helper/connectivity'
|
|
57
|
+
export * from './helper/displayAlreadyInitializedError'
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { toStackTraceString } from '../helper/errorTools'
|
|
2
2
|
import { mergeObservables, Observable } from '../helper/observable'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
includes,
|
|
5
|
+
safeTruncate,
|
|
6
|
+
filter,
|
|
7
|
+
each,
|
|
8
|
+
assign,
|
|
9
|
+
clocksNow
|
|
10
|
+
} from '../helper/tools'
|
|
4
11
|
import { addEventListener } from '../browser/addEventListener'
|
|
5
12
|
import { DOM_EVENT } from '../helper/enums'
|
|
6
13
|
import { monitor } from '../helper/monitor'
|
|
@@ -33,7 +40,7 @@ function createReportObservable(reportTypes) {
|
|
|
33
40
|
|
|
34
41
|
var handleReports = monitor(function (reports) {
|
|
35
42
|
each(reports, function (report) {
|
|
36
|
-
observable.notify(
|
|
43
|
+
observable.notify(buildRawReportErrorFromReport(report))
|
|
37
44
|
})
|
|
38
45
|
})
|
|
39
46
|
|
|
@@ -47,34 +54,29 @@ function createReportObservable(reportTypes) {
|
|
|
47
54
|
observer.disconnect()
|
|
48
55
|
}
|
|
49
56
|
})
|
|
50
|
-
|
|
51
|
-
return observable
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
function createCspViolationReportObservable(configuration) {
|
|
55
60
|
return new Observable(function (observable) {
|
|
56
|
-
var handleCspViolation = function (event) {
|
|
57
|
-
observable.notify(buildRawReportFromCspViolation(event))
|
|
58
|
-
}
|
|
59
|
-
|
|
60
61
|
var _addEventListener = addEventListener(
|
|
61
62
|
document,
|
|
62
63
|
DOM_EVENT.SECURITY_POLICY_VIOLATION,
|
|
63
|
-
|
|
64
|
+
function (event) {
|
|
65
|
+
observable.notify(buildRawReportErrorFromCspViolation(event))
|
|
66
|
+
}
|
|
64
67
|
)
|
|
65
68
|
|
|
66
69
|
return _addEventListener.stop
|
|
67
70
|
})
|
|
68
|
-
return observable
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
function
|
|
73
|
+
function buildRawReportErrorFromReport(report) {
|
|
72
74
|
var body = report.body
|
|
73
75
|
var type = report.type
|
|
74
|
-
return {
|
|
75
|
-
type:
|
|
76
|
-
subtype: body.id,
|
|
76
|
+
return buildRawReportError({
|
|
77
|
+
type: body.id,
|
|
77
78
|
message: type + ': ' + body.message,
|
|
79
|
+
originalError: report,
|
|
78
80
|
stack: buildStack(
|
|
79
81
|
body.id,
|
|
80
82
|
body.message,
|
|
@@ -82,32 +84,46 @@ function buildRawReportFromReport(report) {
|
|
|
82
84
|
body.lineNumber,
|
|
83
85
|
body.columnNumber
|
|
84
86
|
)
|
|
85
|
-
}
|
|
87
|
+
})
|
|
86
88
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
function buildRawReportError(partial) {
|
|
90
|
+
return assign(
|
|
91
|
+
{
|
|
92
|
+
startClocks: clocksNow(),
|
|
93
|
+
source: ErrorSource.REPORT,
|
|
94
|
+
handling: ErrorHandling.UNHANDLED
|
|
95
|
+
},
|
|
96
|
+
partial
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
function buildRawReportErrorFromCspViolation(event) {
|
|
90
100
|
var message =
|
|
91
101
|
"'" +
|
|
92
102
|
event.blockedURI +
|
|
93
103
|
"' blocked by '" +
|
|
94
104
|
event.effectiveDirective +
|
|
95
105
|
"' directive"
|
|
96
|
-
return {
|
|
97
|
-
type:
|
|
98
|
-
|
|
99
|
-
|
|
106
|
+
return buildRawReportError({
|
|
107
|
+
type: event.effectiveDirective,
|
|
108
|
+
message: RawReportType.cspViolation + ': ' + message,
|
|
109
|
+
originalError: event,
|
|
110
|
+
csp: {
|
|
111
|
+
disposition: event.disposition
|
|
112
|
+
},
|
|
100
113
|
stack: buildStack(
|
|
101
114
|
event.effectiveDirective,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
115
|
+
event.originalPolicy
|
|
116
|
+
? `${message} of the policy "${safeTruncate(
|
|
117
|
+
event.originalPolicy,
|
|
118
|
+
100,
|
|
119
|
+
'...'
|
|
120
|
+
)}"`
|
|
121
|
+
: 'no policy',
|
|
106
122
|
event.sourceFile,
|
|
107
123
|
event.lineNumber,
|
|
108
124
|
event.columnNumber
|
|
109
125
|
)
|
|
110
|
-
}
|
|
126
|
+
})
|
|
111
127
|
}
|
|
112
128
|
|
|
113
129
|
function buildStack(name, message, sourceFile, lineNumber, columnNumber) {
|