Skip to content

Commit

Permalink
fix: Clean up xhrWrappable (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwli24 authored Apr 24, 2024
1 parent a518039 commit 5e28fb7
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/common/config/state/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const model = {
/** Agent-specific metadata found in the RUM call response. ex. entityGuid */
appMetadata: {},
session: undefined,
xhrWrappable: typeof globalScope.XMLHttpRequest?.prototype?.addEventListener === 'function',
version: VERSION,
denyList: undefined,
harvestCount: 0,
Expand Down
5 changes: 1 addition & 4 deletions src/features/ajax/instrument/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import { originals, getLoaderConfig, getRuntime } from '../../../common/config/config'
import { originals, getLoaderConfig } from '../../../common/config/config'
import { handle } from '../../../common/event-emitter/handle'
import { id } from '../../../common/ids/id'
import { ffVersion, globalScope, isBrowserScope } from '../../../common/constants/runtime'
Expand All @@ -29,9 +29,6 @@ export class Instrument extends InstrumentBase {
constructor (agentIdentifier, aggregator, auto = true) {
super(agentIdentifier, aggregator, FEATURE_NAME, auto)

// Very unlikely, but in case the existing XMLHttpRequest.prototype object on the page couldn't be wrapped.
if (!getRuntime(agentIdentifier).xhrWrappable) return

this.dt = new DT(agentIdentifier)

this.handler = (type, args, ctx, group) => handle(type, args, ctx, group, this.ee)
Expand Down
4 changes: 0 additions & 4 deletions src/features/session_trace/aggregate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ export class Aggregate extends AggregateBase {
constructor (agentIdentifier, aggregator, argsObj) {
super(agentIdentifier, aggregator, FEATURE_NAME)
this.agentRuntime = getRuntime(agentIdentifier)

// Very unlikely, but in case the existing XMLHttpRequest.prototype object on the page couldn't be wrapped.
if (!this.agentRuntime.xhrWrappable) return

this.resourceObserver = argsObj?.resourceObserver // undefined if observer couldn't be created
this.ptid = ''
this.trace = {}
Expand Down
3 changes: 0 additions & 3 deletions src/features/spa/instrument/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from '../../../common/wrap'
import { eventListenerOpts } from '../../../common/event-listener/event-listener-opts'
import { InstrumentBase } from '../../utils/instrument-base'
import { getRuntime } from '../../../common/config/config'
import * as CONSTANTS from '../constants'
import { isBrowserScope } from '../../../common/constants/runtime'
import { now } from '../../../common/timing/now'
Expand All @@ -22,8 +21,6 @@ export class Instrument extends InstrumentBase {
super(agentIdentifier, aggregator, FEATURE_NAME, auto)
if (!isBrowserScope) return // SPA not supported outside web env

if (!getRuntime(agentIdentifier).xhrWrappable) return

try {
this.removeOnAbort = new AbortController()
} catch (e) {}
Expand Down
1 change: 0 additions & 1 deletion tests/components/session_trace/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ jest.mock('../../../src/common/config/config', () => ({
getConfigurationValue: jest.fn().mockReturnValue(undefined),
isConfigured: jest.fn().mockReturnValue(true),
getRuntime: jest.fn().mockReturnValue({
xhrWrappable: true,
offset: Date.now()
})
}))
Expand Down
2 changes: 1 addition & 1 deletion tests/components/spa/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jest.mock('../../../src/common/config/config', () => ({
ST: setTimeout,
CT: clearTimeout
},
getRuntime: jest.fn().mockReturnValue({ xhrWrappable: true }),
getRuntime: jest.fn().mockReturnValue({}),
isConfigured: jest.fn().mockReturnValue(true),
getInfo: jest.fn()
}))
Expand Down
2 changes: 1 addition & 1 deletion tests/components/spa/initial-page-load.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jest.mock('../../../src/common/config/config', () => ({
__esModule: true,
getConfigurationValue: jest.fn(),
originals: { ST: setTimeout },
getRuntime: jest.fn().mockReturnValue({ xhrWrappable: true }),
getRuntime: jest.fn().mockReturnValue({}),
isConfigured: jest.fn().mockReturnValue(true),
getInfo: jest.fn().mockReturnValue({ jsAttributes: {} })
}))
Expand Down
2 changes: 1 addition & 1 deletion tests/components/spa/nested-timer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jest.mock('../../../src/common/config/config', () => ({
__esModule: true,
getConfigurationValue: jest.fn(),
originals: { ST: setTimeout },
getRuntime: jest.fn().mockReturnValue({ xhrWrappable: true }),
getRuntime: jest.fn().mockReturnValue({}),
isConfigured: jest.fn().mockReturnValue(true),
getInfo: jest.fn().mockReturnValue({ jsAttributes: {} })
}))
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/spa/fetch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ testDriver.test('response size', supported, function (t, browser, router) {
var testCases = [
{
name: 'with request that returns content-length header',
responseBodySize: 10,
responseBodySize: 'abc123'.length,
asset: 'spa/fetch-simple.html'
},
{
Expand Down

0 comments on commit 5e28fb7

Please sign in to comment.