Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add future effort SMs #1371

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/supportability-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ A timeslice metric is harvested to the JSE/XHR consumer. An aggregation service
* Generic/VideoElement/Added
<!--- A <iframe> element was added to the DOM, should have a total count as part of the metric --->
* Generic/IFrame/Added
<!--- The browser being controlled by webDriver was detected --->
* Generic/WebDriver/Detected
<!--- A CSP violation was detected --->
* Generic/CSPViolation/Detected

### Frameworks
<!--- React was Detected --->
Expand Down
3 changes: 3 additions & 0 deletions src/features/metrics/aggregate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ export class Aggregate extends AggregateBase {
mo.observe(window.document.body, { childList: true, subtree: true })
}

// webdriver detection
if (navigator.webdriver) this.storeSupportabilityMetrics('Generic/WebDriver/Detected')

WATCHABLE_WEB_SOCKET_EVENTS.forEach(tag => {
registerHandler('buffered-' + WEBSOCKET_TAG + tag, (...args) => {
handleWebsocketEvents(this.storeSupportabilityMetrics.bind(this), tag, ...args)
Expand Down
13 changes: 12 additions & 1 deletion src/features/metrics/instrument/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { isBrowserScope } from '../../../common/constants/runtime'
import { handle } from '../../../common/event-emitter/handle'
import { WEBSOCKET_TAG, wrapWebSocket } from '../../../common/wrap/wrap-websocket'
import { InstrumentBase } from '../../utils/instrument-base'
import { FEATURE_NAME, WATCHABLE_WEB_SOCKET_EVENTS } from '../constants'
import {
FEATURE_NAME,
WATCHABLE_WEB_SOCKET_EVENTS,
SUPPORTABILITY_METRIC_CHANNEL
} from '../constants'

export class Instrument extends InstrumentBase {
static featureName = FEATURE_NAME
Expand All @@ -20,6 +25,12 @@ export class Instrument extends InstrumentBase {
})
})

if (isBrowserScope) {
document.addEventListener('securitypolicyviolation', (e) => {
handle(SUPPORTABILITY_METRIC_CHANNEL, ['Generic/CSPViolation/Detected'], undefined, this.featureName, this.ee)
})
}

this.importAggregator(agentRef)
}
}
Expand Down
20 changes: 20 additions & 0 deletions tests/assets/csp-violation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<!--
Copyright 2020 New Relic Corporation.
PDX-License-Identifier: Apache-2.0
-->
<html>
<head>
<title>RUM Unit Test</title>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline'; connect-src *;">
{init} {config} {loader}
</head>
<body>Instrumented
<script>
// This script will trigger a CSP violation
var script = document.createElement('script');
script.src = 'https://example.com';
document.body.appendChild(script);
</script>
</body>
</html>