svg-pan-zoom icon indicating copy to clipboard operation
svg-pan-zoom copied to clipboard

[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive.

Open mihai-craita opened this issue 5 years ago • 9 comments

Hi there!

In your example "SVG Inserted with Embed Element" if you switch to console in development tools of chrome (version 73 or newer) you will receive the following error in console:

[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive.

Expected behaviour

this error should not appear in console

Configuration

  • svg-pan-zoom version: v3.6.0
  • Browser(s): google chrome 79.0
  • Operating system(s): OSX
  • A relevant example URL: http://ariutta.github.io/svg-pan-zoom/demo/embed.html

mihai-craita avatar Jan 06 '20 13:01 mihai-craita

This causes also a bug when you have scrollbars for the page: on svg when you wheel scroll, page scrolls and also svg is zoomed. Affects only Chrome on all platforms as far as I know.

@ariutta would you be able to fix this?

jvaa avatar Feb 26 '20 10:02 jvaa

I also encountered the same issue. Tested on Chrome browser. Can we have this fixed ?

Chrome Debug log: [Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See <URL> svg-pan-zoom.min.js:3 [Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See https://www.chromestatus.com/features/6662647093133312

webyahoo avatar Sep 18 '20 00:09 webyahoo

I found this thread on another github project that provided a solution to a similar issue, hopefully it helps this project as well. https://github.com/inuyaksa/jquery.nicescroll/issues/799

webyahoo avatar Sep 18 '20 01:09 webyahoo

Still not fixed?

aloska avatar Nov 16 '20 06:11 aloska

Replace lines 1580 and 1592 of the unminified code:

1580. elem[ _addEventListener ]( prefix + eventName, cb, useCapture || false ); 1592. elem[ _removeEventListener ]( prefix + eventName, cb, useCapture || false );

...with:

elem[ _addEventListener ]( prefix + eventName, cb, useCapture || { capture: false, passive: false } ); elem[ _removeEventListener ]( prefix + eventName, cb, useCapture || { capture: false, passive: false } );

This solution was adapted from here, which offers an explanation as to what this does and why it works. I haven't thoroughly tested it but it seems to resolve the console errors and allows the SVG to be zoomed without scrolling the page.

CrzLvl avatar Feb 22 '21 07:02 CrzLvl

How about for the minified code?

CodeKazuko avatar Sep 19 '21 02:09 CodeKazuko

My google chrome is Version 96.0.4664.110 (Official Build) (64-bit) This works for me ! But the passiveOption logic is right. The real reason is that we should specify the passiveOption to passive param, not the wront param capture. since the passive param is default true ! i just think this is a problem because a newer chorme version add the additional capture param. so the old svg-pen-zoom code pass the logic correct passiveOption variable to the wrong parameter !

    // elem[_addEventListener](prefix + eventName, cb, isPassiveListener ? passiveOption : false);
    elem[_addEventListener](prefix + eventName, cb, { capture: false, passive: isPassiveListener ? passiveOption : false });

    // elem[_removeEventListener](prefix + eventName, cb, isPassiveListener ? passiveOption : false);
    elem[_removeEventListener](prefix + eventName, cb, { capture: false, passive: isPassiveListener ? passiveOption : false });

sakurawald avatar Apr 30 '22 22:04 sakurawald

I'm still seeing this issue. Any update?

connerkennedy32 avatar Nov 30 '23 17:11 connerkennedy32

Replace lines 1580 and 1592 of the unminified code:

1580. elem[ _addEventListener ]( prefix + eventName, cb, useCapture || false ); 1592. elem[ _removeEventListener ]( prefix + eventName, cb, useCapture || false );

...with:

elem[ _addEventListener ]( prefix + eventName, cb, useCapture || { capture: false, passive: false } ); elem[ _removeEventListener ]( prefix + eventName, cb, useCapture || { capture: false, passive: false } );

This solution was adapted from here, which offers an explanation as to what this does and why it works. I haven't thoroughly tested it but it seems to resolve the console errors and allows the SVG to be zoomed without scrolling the page.

I'm running version 3.12.1. Where do I add this code in this version? I'm having a hard time tracking it down

connerkennedy32 avatar Nov 30 '23 17:11 connerkennedy32