79672517

Date: 2025-06-19 18:56:50
Score: 1
Natty:
Report link

I identified two key issues in my previous tests:

  1. Using stopPropagation() instead of stopImmediatePropagation() - the latter prevents all subsequent handlers from executing
  2. Adding event listeners after Bootstrap was already initialized

Here's the working solution (must be placed before Bootstrap import):

document.addEventListener('click', (event) => {
    if(event.target.nodeName === 'CANVAS') {
        event.stopImmediatePropagation();
    }
}, true);

import('bootstrap/dist/js/bootstrap.min.js');

Although effective, this workaround has limitations:

This approach blocks all click events on canvas elements, affecting both Phaser and Google Tag Manager. In my case, this wasn't problematic since I'm using mouseup/mousedown events in Phaser rather than click events.

If you need click event functionality, you can follow @C3roe's suggestion to stop and then manually re-propagate the event to specific handlers.

An official Bootstrap method to exclude specific DOM elements from event handling would be preferable.

Performance comparison (Before/After)

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @C3roe's
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: ivo