{"version":3,"sources":["node_modules/@newrelic/browser-agent/dist/esm/common/wrap/wrap-events.js","node_modules/@newrelic/browser-agent/dist/esm/common/wrap/wrap-fetch.js","node_modules/@newrelic/browser-agent/dist/esm/common/wrap/wrap-history.js","node_modules/@newrelic/browser-agent/dist/esm/common/wrap/wrap-jsonp.js","node_modules/@newrelic/browser-agent/dist/esm/common/wrap/wrap-mutation.js","node_modules/@newrelic/browser-agent/dist/esm/common/wrap/wrap-promise.js","node_modules/@newrelic/browser-agent/dist/esm/common/wrap/wrap-timer.js","node_modules/@newrelic/browser-agent/dist/esm/common/wrap/wrap-xhr.js"],"sourcesContent":["/*\n * Copyright 2020 New Relic Corporation. All rights reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n/**\n * @file Wraps `addEventListener` and `removeEventListener` for instrumentation.\n * This module is used directly by: session_trace.\n * It is also called by -> wrapXhr <-, so see \"wrap-xhr.js\" for features that use this indirectly.\n */\nimport { ee as baseEE, contextId } from '../event-emitter/contextual-ee';\nimport { createWrapperWithEmitter as wfn } from './wrap-function';\nimport { getOrSet } from '../util/get-or-set';\nimport { globalScope, isBrowserScope } from '../constants/runtime';\nconst wrapped = {};\nconst XHR = globalScope.XMLHttpRequest;\nconst ADD_EVENT_LISTENER = 'addEventListener';\nconst REMOVE_EVENT_LISTENER = 'removeEventListener';\nconst flag = \"nr@wrapped:\".concat(contextId);\n\n/**\n * Wraps `addEventListener` and `removeEventListener` on: global scope; the prototype of `XMLHttpRequest`, and\n * `document` (if in a browser scope). Adds custom events in context of a new emitter scoped only to these methods.\n * @param {Object} sharedEE - The shared event emitter on which a new scoped\n * event emitter will be based.\n * @returns {Object} Scoped event emitter with a debug ID of `events`.\n */\nexport function wrapEvents(sharedEE) {\n var ee = scopedEE(sharedEE);\n\n // Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,\n // then we increment the count to track # of feats using this at runtime.\n if (wrapped[ee.debugId]++) return ee;\n wrapped[ee.debugId] = 1; // otherwise, first feature to wrap events\n var wrapFn = wfn(ee, true);\n\n // Guard against instrumenting environments w/o necessary features\n if ('getPrototypeOf' in Object) {\n if (isBrowserScope) findEventListenerProtoAndCb(document, wrapNode);\n findEventListenerProtoAndCb(globalScope, wrapNode);\n findEventListenerProtoAndCb(XHR.prototype, wrapNode);\n }\n ee.on(ADD_EVENT_LISTENER + '-start', function (args, target) {\n var originalListener = args[1];\n if (originalListener === null || typeof originalListener !== 'function' && typeof originalListener !== 'object') {\n return;\n }\n var wrapped = getOrSet(originalListener, flag, function () {\n var listener = {\n object: wrapHandleEvent,\n function: originalListener\n }[typeof originalListener];\n return listener ? wrapFn(listener, 'fn-', null, listener.name || 'anonymous') : originalListener;\n function wrapHandleEvent() {\n if (typeof originalListener.handleEvent !== 'function') return;\n return originalListener.handleEvent.apply(originalListener, arguments);\n }\n });\n this.wrapped = args[1] = wrapped;\n });\n ee.on(REMOVE_EVENT_LISTENER + '-start', function (args) {\n args[1] = this.wrapped || args[1];\n });\n function wrapNode(node) {\n wrapFn.inPlace(node, [ADD_EVENT_LISTENER, REMOVE_EVENT_LISTENER], '-', uniqueListener);\n }\n function uniqueListener(args, obj) {\n // Context for the listener is stored on itself.\n return args[1];\n }\n return ee;\n}\n/**\n * Find the base prototype of 'object' that has its own \"addEventListener\" property, and run some function on it.\n * @param {Object} object - the initial object to traverse prototype chain on\n * @param {Function} cb - the function to run on the ancestral object once found, accepts an object as a arg\n * @param {Array} rest - [optional] any additional arguments to pass to the cb\n */\nfunction findEventListenerProtoAndCb(object, cb) {\n let step = object;\n while (typeof step === 'object' && !Object.prototype.hasOwnProperty.call(step, ADD_EVENT_LISTENER)) {\n step = Object.getPrototypeOf(step);\n }\n for (var _len = arguments.length, rest = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {\n rest[_key - 2] = arguments[_key];\n }\n if (step) cb(step, ...rest);\n}\n\n/**\n * Returns an event emitter scoped specifically for the `events` context. This scoping is a remnant from when all the\n * features shared the same group in the event, to isolate events between features. It will likely be revisited.\n * @param {Object} sharedEE - Optional event emitter on which to base the scoped emitter.\n * Uses `ee` on the global scope if undefined).\n * @returns {Object} Scoped event emitter with a debug ID of 'events'.\n */\nexport function scopedEE(sharedEE) {\n return (sharedEE || baseEE).get('events');\n}","/*\n * Copyright 2020 New Relic Corporation. All rights reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n/**\n * @file Wraps `fetch` and related methods for instrumentation.\n * This module is used by: ajax, spa.\n */\nimport { ee as baseEE, contextId } from '../event-emitter/contextual-ee';\nimport { globalScope } from '../constants/runtime';\nvar prefix = 'fetch-';\nvar bodyPrefix = prefix + 'body-';\nvar bodyMethods = ['arrayBuffer', 'blob', 'json', 'text', 'formData'];\nvar Req = globalScope.Request;\nvar Res = globalScope.Response;\nvar proto = 'prototype';\nconst wrapped = {};\n\n/**\n * Wraps the `fetch` method of the global scope for instrumentation. Also wraps the prototypes of the async methods\n * that parse Request and Response bodies to generate start and end events for each, in context of a new event\n * emitter scoped only to fetch and related methods.\n * @param {Object} sharedEE - The shared event emitter on which a new scoped\n * event emitter will be based.\n * @returns {Object} Scoped event emitter with a debug ID of `fetch`.\n */\nexport function wrapFetch(sharedEE) {\n const ee = scopedEE(sharedEE);\n if (!(Req && Res && globalScope.fetch)) {\n return ee;\n }\n\n // Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,\n // then we increment the count to track # of feats using this at runtime.\n if (wrapped[ee.debugId]++) return ee;\n wrapped[ee.debugId] = 1; // otherwise, first feature to wrap fetch\n\n bodyMethods.forEach(method => {\n wrapPromiseMethod(Req[proto], method, bodyPrefix);\n wrapPromiseMethod(Res[proto], method, bodyPrefix);\n });\n wrapPromiseMethod(globalScope, 'fetch', prefix);\n ee.on(prefix + 'end', function (err, res) {\n var ctx = this;\n if (res) {\n var size = res.headers.get('content-length');\n if (size !== null) {\n ctx.rxSize = size;\n }\n ee.emit(prefix + 'done', [null, res], ctx);\n } else {\n ee.emit(prefix + 'done', [err], ctx);\n }\n });\n\n /**\n * Wraps a Promise-returning function (referenced by `target[name]`) to emit custom events before and after\n * execution, each decorated with metadata (arguments, payloads, errors). Used to wrap the async body\n * parsing methods of Request and Response (e.g. `json`, `text`, `formData`).\n * @param {Object} target - The object having the method to be wrapped.\n * @param {string} name - The name of the method to wrap.\n * @param {string} prefix - Used to decorate event names with context.\n */\n function wrapPromiseMethod(target, name, prefix) {\n var fn = target[name];\n if (typeof fn === 'function') {\n target[name] = function () {\n var args = [...arguments];\n var ctx = {};\n // we are wrapping args in an array so we can preserve the reference\n ee.emit(prefix + 'before-start', [args], ctx);\n var dtPayload;\n if (ctx[contextId] && ctx[contextId].dt) dtPayload = ctx[contextId].dt;\n var origPromiseFromFetch = fn.apply(this, args);\n ee.emit(prefix + 'start', [args, dtPayload], origPromiseFromFetch);\n\n // Note we need to cast the returned (orig) Promise from native APIs into the current global Promise, which may or may not be our WrappedPromise.\n return origPromiseFromFetch.then(function (val) {\n ee.emit(prefix + 'end', [null, val], origPromiseFromFetch);\n return val;\n }, function (err) {\n ee.emit(prefix + 'end', [err], origPromiseFromFetch);\n throw err;\n });\n };\n }\n }\n return ee;\n}\n\n/**\n * Returns an event emitter scoped specifically for the `fetch` context. This scoping is a remnant from when all the\n * features shared the same group in the event, to isolate events between features. It will likely be revisited.\n * @param {Object} sharedEE - Optional event emitter on which to base the scoped emitter.\n * Uses `ee` on the global scope if undefined).\n * @returns {Object} Scoped event emitter with a debug ID of 'fetch'.\n */\nexport function scopedEE(sharedEE) {\n return (sharedEE || baseEE).get('fetch');\n}","/*\n * Copyright 2020 New Relic Corporation. All rights reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n/**\n * @file Wraps `pushState` and `replaceState` methods of `window.history` object for instrumentation.\n * This module is used by: session_trace, spa.\n */\nimport { ee as globalEE } from '../event-emitter/contextual-ee';\nimport { createWrapperWithEmitter as wfn } from './wrap-function';\nimport { isBrowserScope } from '../constants/runtime';\nconst wrapped = {};\nconst HISTORY_FNS = ['pushState', 'replaceState'];\n\n/**\n * Wraps the `pushState` and `replaceState` methods of `window.history` and returns a corresponding event emitter\n * scoped to the history object.\n * @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.\n * @returns {Object} Scoped event emitter with a debug ID of `history`.\n */\nexport function wrapHistory(sharedEE) {\n const ee = scopedEE(sharedEE);\n\n // Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,\n // then we increment the count to track # of feats using this at runtime. History API is only\n // available in browser DOM context.\n if (!isBrowserScope || wrapped[ee.debugId]++) return ee;\n wrapped[ee.debugId] = 1; // otherwise, first feature to wrap history\n\n var wrapFn = wfn(ee);\n /*\n * For objects that will be instantiated more than once, we wrap the object's prototype methods. The history object\n * is instantiated only once, so we can wrap its methods directly--and we must wrap the history methods directly as\n * long as [Chromium issue 783382](https://bugs.chromium.org/p/chromium/issues/detail?id=783382) remains unresolved.\n */\n wrapFn.inPlace(window.history, HISTORY_FNS, '-');\n return ee;\n}\n\n/**\n * Returns an event emitter scoped specifically for the `history` context. This scoping is a remnant from when all the\n * features shared the same group in the event, to isolate events between features. It will likely be revisited.\n * @param {Object} sharedEE - Optional event emitter on which to base the scoped emitter.\n * Uses `ee` on the global scope if undefined).\n * @returns {Object} Scoped event emitter with a debug ID of 'history'.\n */\nexport function scopedEE(sharedEE) {\n return (sharedEE || globalEE).get('history');\n}","/*\n * Copyright 2020 New Relic Corporation. All rights reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n/**\n * @file Wraps DOM insertion methods which in turn wrap JSONP functions that show up in the DOM.\n * This module is used by: spa.\n */\n\nimport { eventListenerOpts } from '../event-listener/event-listener-opts';\nimport { ee as baseEE } from '../event-emitter/contextual-ee';\nimport { createWrapperWithEmitter as wfn } from './wrap-function';\nimport { isBrowserScope } from '../constants/runtime';\nconst wrapped = {};\nconst domInsertMethods = ['appendChild', 'insertBefore', 'replaceChild'];\n\n/**\n * Wraps DOM insertion methods to identify script elements containing JSONP callback functions and instruments those\n * functions with custom events in the context of a new event emitter scoped only to JSONP.\n * @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.\n * @returns {Object} Scoped event emitter with a debug ID of `jsonp`.\n */\nexport function wrapJsonP(sharedEE) {\n const ee = scopedEE(sharedEE);\n\n // Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,\n // then we increment the count to track # of feats using this at runtime. JSONP deals with DOM\n // tags so browser window env is required.\n if (!isBrowserScope || wrapped[ee.debugId]) return ee;\n wrapped[ee.debugId] = true; // otherwise, first feature to wrap JSONP\n\n var wrapFn = wfn(ee);\n var CALLBACK_REGEX = /[?&](?:callback|cb)=([^&#]+)/;\n var PARENT_REGEX = /(.*)\\.([^.]+)/;\n var VALUE_REGEX = /^(\\w+)(\\.|$)(.*)$/;\n\n // JSONP works by dynamically inserting