-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
77 lines (66 loc) · 2.99 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* @flow */
import 'core-js/fn/array/filter';
import 'core-js/fn/array/find';
import 'core-js/fn/string/starts-with';
import CommandExecutor from './CommandExecutor';
import PageLoadDispatcher from './dispatchers/PageLoadDispatcher';
import RumUploader from './RumUploader';
import bootstrap from './bootstrap';
import AjaxDispatcher from './dispatchers/AjaxDispatcher';
import { GLOBAL_KEY } from './constants';
import { setupContext, keepSessionAlive } from './common';
import patchXhr from './ajax/xhr';
import patchFetch from './ajax/fetch';
import DocumentVisibilityObserver from './DocumentVisibilityObserver';
import ElementTimingDispatcher from './dispatchers/ElementTimingDispatcher';
import WebVitalsDispatcher from './dispatchers/WebVitalsDispatcher';
import MemoryUsageDispatcher from './dispatchers/MemoryUsageDispatcher';
import MeasureDispatcher from './dispatchers/MeasureDispatcher';
const contextNames = window.STRUM_CONTEXTS || [GLOBAL_KEY];
let ignoreList = window.STRUM_IGNORE_AJAX;
if (ignoreList === null || ignoreList === undefined) {
ignoreList = [];
}
patchXhr(window, ignoreList);
patchFetch(window, ignoreList);
const visibilityObserver = new DocumentVisibilityObserver();
const pageLoadDispatcher = new PageLoadDispatcher();
const ajaxDispatcher = new AjaxDispatcher();
const elementTimingDispatcher = new ElementTimingDispatcher();
const webVitalsDispatcher = new WebVitalsDispatcher();
const memoryUsageDispatcher = new MemoryUsageDispatcher();
const measureDispatcher = new MeasureDispatcher();
visibilityObserver.addListener(pageLoadDispatcher);
visibilityObserver.addListener(ajaxDispatcher);
visibilityObserver.addListener(elementTimingDispatcher);
visibilityObserver.addListener(measureDispatcher);
// DON'T: visibilityObserver.addListener(webVitalsDispatcher);
// we're not adding web vitals dispatcher to the visibility observer because we
// don't control the implementation of how metric are collected and I believe
// that web-vitals already does some visibility change handling.
// We don't want to add memoryUsageDispatcher to visibility observer as well.
contextNames.forEach((contextName) => {
const context = setupContext(contextName);
keepSessionAlive(context.sessionID);
const uploader = new RumUploader(context, contextName);
context.uploader = uploader;
const executor = new CommandExecutor(context, contextName);
visibilityObserver.addListener(executor);
bootstrap(executor, window, contextName).then(() => {
pageLoadDispatcher.addExecutor(executor);
ajaxDispatcher.addExecutor(executor);
elementTimingDispatcher.addExecutor(executor);
webVitalsDispatcher.addExecutor(executor);
memoryUsageDispatcher.addExecutor(executor);
measureDispatcher.addExecutor(executor);
});
});
// start page load and ajax dispatchers
pageLoadDispatcher.start();
ajaxDispatcher.start();
elementTimingDispatcher.start();
webVitalsDispatcher.start();
memoryUsageDispatcher.start();
measureDispatcher.start();
// start observing visibility changes
visibilityObserver.startListening();