-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathcustomActionButtons.js
More file actions
123 lines (105 loc) · 3.37 KB
/
Copy pathcustomActionButtons.js
File metadata and controls
123 lines (105 loc) · 3.37 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { LightningElement, track } from 'lwc'
export default class CustomActionButtons extends LightningElement {
@track lastActionName
@track lastErrorName
@track lastResourceName
@track lastSelectorProbe
handleActionClick(event) {
const actionName = event.currentTarget.dataset.actionName
this.lastActionName = actionName
window.DD_RUM?.addAction(actionName, {
source: 'salesforce-home-button',
pathname: window.location?.pathname,
})
}
handleErrorClick(event) {
const errorName = event.currentTarget.dataset.errorName
this.lastErrorName = errorName
window.DD_RUM?.addError(new Error(errorName), {
source: 'salesforce-home-button',
pathname: window.location?.pathname,
})
}
handleRuntimeErrorClick() {
throw new Error('salesforce direct runtime error test')
}
handleLongTaskClick() {
window.setTimeout(() => {
const start = performance.now()
while (performance.now() - start < 750) {
/* spin */
}
}, 0)
}
// Vitals: report a completed duration vital directly.
handleAddDurationVitalClick() {
window.DD_RUM?.addDurationVital('salesforce.duration_vital_test', {
startTime: Date.now() - 250,
duration: 250,
description: 'salesforce duration vital test',
context: {
source: 'salesforce-home-button',
},
})
}
// Vitals: measure a live 300ms window.
handleStartStopVitalClick() {
window.DD_RUM?.startDurationVital('salesforce.start_stop_vital_test', {
description: 'salesforce start-stop vital test',
context: {
source: 'salesforce-home-button',
},
})
setTimeout(() => window.DD_RUM?.stopDurationVital('salesforce.start_stop_vital_test'), 300)
}
async handleFetchResourceClick() {
const token = `dd-fetch-test-${Date.now()}`
const url = this.getResourceTestUrl(token)
this.lastResourceName = `fetch: ${token}`
try {
const response = await window.fetch(url, { cache: 'no-store' })
await response.text()
} catch (error) {
window.DD_RUM?.addError(error, {
source: 'salesforce-resource-button',
resourceType: 'fetch',
url,
})
}
}
handleXhrResourceClick() {
const token = `dd-xhr-test-${Date.now()}`
const url = this.getResourceTestUrl(token)
this.lastResourceName = `xhr: ${token}`
const xhr = new window.XMLHttpRequest()
xhr.open('GET', url)
xhr.onerror = () => {
window.DD_RUM?.addError(new Error('salesforce xhr resource test failed'), {
source: 'salesforce-resource-button',
resourceType: 'xhr',
url,
})
}
xhr.send()
}
handleSelectorProbeClick(event) {
const innerActionName = event.currentTarget.getAttribute('data-dd-action-name')
this.lastSelectorProbe = innerActionName
window.DD_RUM?.addAction('selector probe internal target', {
source: 'salesforce-selector-probe',
currentTargetActionName: innerActionName,
currentTargetTagName: event.currentTarget.tagName,
targetTagName: event.target.tagName,
composedPath: this.getComposedPathNames(event),
})
}
getResourceTestUrl(token) {
return `${window.location.origin}/services/data/?${token}`
}
getComposedPathNames(event) {
return event
.composedPath()
.slice(0, 6)
.map((target) => target.tagName || target.nodeName || String(target))
}
}