in src/lib/api/event.recorder.ts [52:102]
export function start(prebootData: PrebootData, win?: PrebootWindow) {
const theWindow = <PrebootWindow>(win || window);
const _document = <Document>(theWindow.document || {});
// Remove the current script from the DOM so that child indexes match
// between the client & the server. The script is already running so it
// doesn't affect it.
const currentScript = _document.currentScript ||
// Support: IE 9-11 only
// IE doesn't support document.currentScript. Since the script is invoked
// synchronously, though, the current running script is just the last one
// currently in the document.
[].slice.call(_document.getElementsByTagName('script'), -1)[0];
if (!currentScript) {
console.error('Preboot initialization failed, no currentScript has been detected.');
return;
}
let serverNode = currentScript.parentNode;
if (!serverNode) {
console.error('Preboot initialization failed, the script is detached');
return;
}
serverNode.removeChild(currentScript);
const opts = prebootData.opts || ({} as PrebootOptions);
let eventSelectors = opts.eventSelectors || [];
// get the root info
const appRoot = prebootData.opts ? getAppRoot(_document, prebootData.opts, serverNode) : null;
// we track all events for each app in the prebootData object which is on
// the global scope; each `start` invocation adds data for one app only.
const appData = <PrebootAppData>{ root: appRoot, events: [] };
if (prebootData.apps) {
prebootData.apps.push(appData);
}
eventSelectors = eventSelectors.map(eventSelector => {
if (!eventSelector.hasOwnProperty('replay')) {
eventSelector.replay = true;
}
return eventSelector;
});
// loop through all the eventSelectors and create event handlers
eventSelectors.forEach(eventSelector =>
handleEvents(_document, prebootData, appData, eventSelector));
}