|
| 1 | +function createContainer(id: string, title: string, borderColor: string) { |
| 2 | + const container = document.createElement('div') |
| 3 | + container.id = id |
| 4 | + container.style.flex = '1' |
| 5 | + container.style.border = `2px solid ${borderColor}` |
| 6 | + container.style.padding = '10px' |
| 7 | + |
| 8 | + const appTitle = document.createElement('h2') |
| 9 | + appTitle.textContent = title |
| 10 | + container.appendChild(appTitle) |
| 11 | + document.body.appendChild(container) |
| 12 | + return container |
| 13 | +} |
| 14 | + |
| 15 | +function createButton(container: HTMLElement, eventType: string, clickHandler: () => void) { |
| 16 | + const button = document.createElement('button') |
| 17 | + button.id = `${container.id}-${eventType}` |
| 18 | + button.textContent = `${container.id}-${eventType}` |
| 19 | + button.onclick = clickHandler |
| 20 | + container.appendChild(button) |
| 21 | +} |
| 22 | + |
| 23 | +export function createApp(id: string, title: string, borderColor: string) { |
| 24 | + const container = createContainer(id, title, borderColor) |
| 25 | + |
| 26 | + createButton(container, 'fetch', () => { |
| 27 | + void fetch('/ok') |
| 28 | + }) |
| 29 | + |
| 30 | + createButton(container, 'xhr', () => { |
| 31 | + const xhr = new XMLHttpRequest() |
| 32 | + xhr.open('GET', '/ok') |
| 33 | + xhr.send() |
| 34 | + }) |
| 35 | + |
| 36 | + createButton(container, 'error', () => { |
| 37 | + window.DD_RUM.addError(new Error(`${id}-error`)) |
| 38 | + }) |
| 39 | + |
| 40 | + createButton(container, 'console-error', () => { |
| 41 | + console.error(`${id}-console-error`) |
| 42 | + }) |
| 43 | + |
| 44 | + createButton(container, 'runtime-error', () => { |
| 45 | + throw new Error(`${id}-runtime-error`) |
| 46 | + }) |
| 47 | + |
| 48 | + createButton(container, 'loaf', () => { |
| 49 | + const end = performance.now() + 55 |
| 50 | + while (performance.now() < end) { |
| 51 | + // block the handler for ~55ms to trigger a long task |
| 52 | + } |
| 53 | + }) |
| 54 | + |
| 55 | + createButton(container, 'custom-action', () => { |
| 56 | + window.DD_RUM.addAction(`${id}-action`) |
| 57 | + }) |
| 58 | + |
| 59 | + createButton(container, 'vital', () => { |
| 60 | + const ref = window.DD_RUM.startDurationVital(`${id}-vital`) |
| 61 | + window.DD_RUM.stopDurationVital(ref) |
| 62 | + }) |
| 63 | + |
| 64 | + createButton(container, 'view', () => { |
| 65 | + window.DD_RUM.startView({ name: `${id}-view` }) |
| 66 | + }) |
| 67 | +} |
0 commit comments