Skip to content

Commit 57feedf

Browse files
committed
style: update button labels for clarity and enhance breadcrumb output messages in sample-errors.js
1 parent 968dd50 commit 57feedf

3 files changed

Lines changed: 71 additions & 71 deletions

File tree

packages/javascript/example/index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,12 @@ <h2>Breadcrumbs Management</h2>
207207
<div id="breadcrumbs-output" style="margin-top: 15px; margin-bottom: 30px; padding: 10px; background: rgba(36, 39, 50, 0.68); border-radius: 3px; max-height: 200px; overflow-y: auto; white-space: pre-wrap; font-family: monospace; font-size: 12px;"></div>
208208
<h2>Test All Breadcrumb Types <small>Quick examples for each type</small></h2>
209209
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;">
210-
<button id="btn-test-default">Default Event</button>
211-
<button id="btn-test-request">Request (Fetch)</button>
212-
<button id="btn-test-ui">UI Click</button>
213-
<button id="btn-test-navigation">Navigation</button>
214-
<button id="btn-test-logic">Logic Operation</button>
215-
<button id="btn-test-error">Error Event</button>
210+
<button id="btn-test-default">Default Event (Manual)</button>
211+
<button id="btn-test-request">Request (Auto via Fetch)</button>
212+
<button id="btn-test-ui">UI Click (Auto)</button>
213+
<button id="btn-test-navigation">Navigation (Auto)</button>
214+
<button id="btn-test-logic">Logic Operation (Manual)</button>
215+
<button id="btn-test-error">Error Event (Manual)</button>
216216
</div>
217217
<div style="margin-top: 10px; display: flex; gap: 10px;">
218218
<button id="btn-test-all-types" style="flex: 1; background: #2ecc71;">▶Run All Types Sequence</button>

packages/javascript/example/sample-errors.js

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,12 @@ const buttonTestError = document.getElementById('btn-test-error');
187187
const buttonTestAllTypes = document.getElementById('btn-test-all-types');
188188

189189
/**
190-
* Test Default breadcrumb
190+
* Test Default breadcrumb (manual)
191191
*/
192192
buttonTestDefault.addEventListener('click', () => {
193+
/**
194+
* Default breadcrumbs are always added manually via hawk.breadcrumbs.add()
195+
*/
193196
window.hawk.breadcrumbs.add({
194197
type: 'default',
195198
level: 'info',
@@ -200,7 +203,7 @@ buttonTestDefault.addEventListener('click', () => {
200203
context: 'breadcrumb_testing',
201204
},
202205
});
203-
breadcrumbsOutput.textContent = '✓ Default breadcrumb added';
206+
breadcrumbsOutput.textContent = '✓ Default breadcrumb added manually';
204207
});
205208

206209
/**
@@ -219,56 +222,53 @@ buttonTestRequest.addEventListener('click', async () => {
219222
});
220223

221224
/**
222-
* Test UI breadcrumb
225+
* Test UI breadcrumb (automatic tracking)
223226
*/
224227
buttonTestUI.addEventListener('click', () => {
225-
window.hawk.breadcrumbs.add({
226-
type: 'ui',
227-
level: 'info',
228-
category: 'ui.click',
229-
message: 'Click on test button#btn-test-ui',
230-
data: {
231-
selector: 'button#btn-test-ui',
232-
text: '👆 UI Click',
233-
tagName: 'BUTTON',
234-
coordinates: {
235-
x: 100,
236-
y: 200,
237-
},
238-
},
239-
});
240-
breadcrumbsOutput.textContent = '✓ UI Click breadcrumb added';
228+
/**
229+
* Create a test element and click it to trigger automatic UI breadcrumb
230+
* BreadcrumbManager automatically captures click events when trackClicks: true
231+
*/
232+
const testElement = document.createElement('button');
233+
234+
testElement.id = 'auto-click-test';
235+
testElement.className = 'test-button';
236+
testElement.textContent = 'Auto Test';
237+
testElement.style.position = 'absolute';
238+
testElement.style.opacity = '0';
239+
testElement.style.pointerEvents = 'none';
240+
document.body.appendChild(testElement);
241+
242+
/**
243+
* Trigger a click event
244+
*/
245+
testElement.click();
246+
247+
/**
248+
* Clean up
249+
*/
250+
setTimeout(() => {
251+
document.body.removeChild(testElement);
252+
}, 100);
253+
254+
breadcrumbsOutput.textContent = '✓ UI Click breadcrumb added automatically';
241255
});
242256

243257
/**
244-
* Test Navigation breadcrumb
258+
* Test Navigation breadcrumb (automatic tracking)
245259
*/
246260
buttonTestNavigation.addEventListener('click', () => {
247-
const currentUrl = window.location.href;
248-
const testUrl = currentUrl.split('#')[0] + '#breadcrumb-test-' + Date.now();
249-
250-
window.hawk.breadcrumbs.add({
251-
type: 'navigation',
252-
level: 'info',
253-
category: 'navigation',
254-
message: `Navigated to ${testUrl}`,
255-
data: {
256-
from: currentUrl,
257-
to: testUrl,
258-
method: 'hash_change',
259-
},
260-
});
261-
262261
/**
263-
* Actually change the hash to trigger real navigation breadcrumb too
262+
* Change the hash to trigger automatic navigation breadcrumb
263+
* BreadcrumbManager automatically captures this event
264264
*/
265265
window.location.hash = 'breadcrumb-test-' + Date.now();
266266

267-
breadcrumbsOutput.textContent = '✓ Navigation breadcrumb added';
267+
breadcrumbsOutput.textContent = '✓ Navigation breadcrumb added automatically';
268268
});
269269

270270
/**
271-
* Test Logic breadcrumb
271+
* Test Logic breadcrumb (manual)
272272
*/
273273
buttonTestLogic.addEventListener('click', () => {
274274
/**
@@ -295,6 +295,9 @@ buttonTestLogic.addEventListener('click', () => {
295295
const result = complexCalculation(10000);
296296
const duration = performance.now() - startTime;
297297

298+
/**
299+
* Logic breadcrumbs are always added manually to track application flow
300+
*/
298301
window.hawk.breadcrumbs.add({
299302
type: 'logic',
300303
level: 'debug',
@@ -308,11 +311,11 @@ buttonTestLogic.addEventListener('click', () => {
308311
},
309312
});
310313

311-
breadcrumbsOutput.textContent = `✓ Logic breadcrumb added (${duration.toFixed(2)}ms)`;
314+
breadcrumbsOutput.textContent = `✓ Logic breadcrumb added manually (${duration.toFixed(2)}ms)`;
312315
});
313316

314317
/**
315-
* Test Error breadcrumb
318+
* Test Error breadcrumb (manual)
316319
*/
317320
buttonTestError.addEventListener('click', () => {
318321
try {
@@ -321,6 +324,10 @@ buttonTestError.addEventListener('click', () => {
321324
*/
322325
JSON.parse('invalid json {{{');
323326
} catch (error) {
327+
/**
328+
* Caught errors can be manually added as breadcrumbs
329+
* Uncaught errors are sent to Hawk automatically, not as breadcrumbs
330+
*/
324331
window.hawk.breadcrumbs.add({
325332
type: 'error',
326333
level: 'error',
@@ -333,7 +340,7 @@ buttonTestError.addEventListener('click', () => {
333340
},
334341
});
335342

336-
breadcrumbsOutput.textContent = `✓ Error breadcrumb added: ${error.message}`;
343+
breadcrumbsOutput.textContent = `✓ Error breadcrumb added manually: ${error.message}`;
337344
}
338345
});
339346

@@ -370,22 +377,22 @@ buttonTestAllTypes.addEventListener('click', async () => {
370377
await new Promise(resolve => setTimeout(resolve, 200));
371378

372379
/**
373-
* 3. UI
380+
* 3. UI (automatic)
374381
*/
375-
window.hawk.breadcrumbs.add({
376-
type: 'ui',
377-
level: 'info',
378-
category: 'ui.interaction',
379-
message: 'User initiated sequence',
380-
data: {
381-
action: 'sequence_test',
382-
},
383-
});
382+
const autoClickElement = document.createElement('button');
383+
384+
autoClickElement.id = 'sequence-auto-click';
385+
autoClickElement.style.position = 'absolute';
386+
autoClickElement.style.opacity = '0';
387+
autoClickElement.style.pointerEvents = 'none';
388+
document.body.appendChild(autoClickElement);
389+
autoClickElement.click();
390+
document.body.removeChild(autoClickElement);
384391

385392
await new Promise(resolve => setTimeout(resolve, 200));
386393

387394
/**
388-
* 4. Request
395+
* 4. Request (automatic)
389396
*/
390397
try {
391398
await fetch('https://api.github.com/zen');
@@ -398,16 +405,9 @@ buttonTestAllTypes.addEventListener('click', async () => {
398405
await new Promise(resolve => setTimeout(resolve, 200));
399406

400407
/**
401-
* 5. Navigation
408+
* 5. Navigation (automatic)
402409
*/
403-
window.hawk.breadcrumbs.add({
404-
type: 'navigation',
405-
level: 'info',
406-
message: 'Internal route change',
407-
data: {
408-
route: '/test',
409-
},
410-
});
410+
window.location.hash = 'sequence-test-' + Date.now();
411411

412412
await new Promise(resolve => setTimeout(resolve, 200));
413413

packages/javascript/src/addons/breadcrumbs.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,13 @@ export class BreadcrumbManager {
270270
}
271271

272272
/**
273-
* Add to buffer (FIFO)
273+
* Add to buffer (FIFO - keep last N breadcrumbs)
274274
*/
275-
if (this.breadcrumbs.length >= this.options.maxBreadcrumbs) {
275+
this.breadcrumbs.push(bc);
276+
277+
if (this.breadcrumbs.length > this.options.maxBreadcrumbs) {
276278
this.breadcrumbs.shift();
277279
}
278-
279-
this.breadcrumbs.push(bc);
280280
}
281281

282282
/**

0 commit comments

Comments
 (0)