interact.js: Uncaught TypeError: Cannot read property 'pageX' of undefined

This error originates from the pointerMove event listener, initiating a call chain to setEventXY and getPageXY, where evidently the pointer is has been passed in as undefined.

Seen on Google Chrome and Chrome Mobile, running on WIndows 8.1, Android 4.4, Windows (version undefined) and Linux.

getPageXY should handle null pointer exceptions (no pun intended).

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 5
  • Comments: 55 (24 by maintainers)

Most upvoted comments

I’ve pushed a thing to the stable branch to avoid PointerEvents in Chrome. If you’re using v1.2.*, updating to v1.2.8 should solve this issue when it’s related to PointerEvents.

@taye I haven’t tried the unstable branch, but I can easily reproduce this issue in Chrome 55.0.2883.75 on http://interactjs.io/

Steps to reproduce:

  1. Make sure your browser window is not maximized.
  2. Open the Chrome Developer Tools console.
  3. Visit http://interactjs.io/
  4. Move your mouse off of, then back onto the browser window again.
  5. Observe that each time your mouse moves onto the browser window, Uncaught TypeError: Cannot read property 'pageX' of undefined appears in the console.

Alternative reproduction: The error appears simply by moving your mouse onto the webpage from the browser chrome area (tabs, address bar, bookmarks, etc).

I get (above) error “Cannot read property ‘pageX’ of undefined” when moving my mouse in and out of the chrome browser window

Same issue here.

Could you please update the download on interact.io to version 1.2.8? Thanks!

I’m sorry for the not sorting this out after so long. I’ll begin to investigate this issue again in the coming days.

There’s a new unstable build. Please update and and report any issues. A demo to reproduce this bug would be very helpful as I haven’t encountered it.

in the meantime, you can use the 1.2.8 version from a CDN.

https://cdnjs.cloudflare.com/ajax/libs/interact.js/1.2.8/interact.js

Here is the stacktrace I am getting for this error:

Uncaught TypeError: Cannot read property 'pageX' of undefined interact.js:649 
getXY @ interact.js:649
getPageXY @ interact.js:666
setEventXY @ interact.js:610
Interaction.setEventXY @ interact.js:1319
Interaction.pointerMove @ interact.js:1782
(anonymous function) @ interact.js:3323

It seems that in some cases, using touch events, the this.addPointer(pointer) is not called and pointer is not added to this.pointers array and becomes undefined as @73rhodes mentioned. One, not perfect but possible way would be to call this.addPointer(pointer) once it’s not found during recording:

  recordPointer: function (pointer) {
        var index = this.mouse? 0: indexOf(this.pointerIds, getPointerId(pointer));
        if (index === -1) {
            this.addPointer(pointer);
            return;
        }
        this.pointers[index] = pointer;
    }

We’re seeing the exact same issue reported too, however I’m not able to replicate it on demand myself.

I’m using leaflet.js on the page, and get this error when dragging the map…

The unstable branch doesn’t work for me (using browserify) Cannot find module './src/utils/window' from 'node_modules/interact.js/dist