@@ -187,9 +187,12 @@ const buttonTestError = document.getElementById('btn-test-error');
187187const buttonTestAllTypes = document . getElementById ( 'btn-test-all-types' ) ;
188188
189189/**
190- * Test Default breadcrumb
190+ * Test Default breadcrumb (manual)
191191 */
192192buttonTestDefault . 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 */
224227buttonTestUI . 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 */
246260buttonTestNavigation . 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 */
273273buttonTestLogic . 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 */
317320buttonTestError . 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
0 commit comments