โ Answer
[object PointerEvent] is the default string form of a JavaScript PointerEvent object (you see it when the event is coerced to a string); to inspect the actual data, log the event object or read its properties like pointerId, clientX, clientY, pointerType, etc.
๐ข Step-by-Step Solution
- Add a pointer event listener and log the event object (best for devtools inspection):
element.addEventListener('pointerdown', e => {
console.log(e); // shows expandable object in DevTools
console.dir(e); // shows object properties in detail
});
- Donโt coerce the event to a string (this produces
"[object PointerEvent]"):
element.addEventListener('pointerdown', e => {
alert(e); // shows "[object PointerEvent]"
console.log('' + e); // also prints "[object PointerEvent]"
});
- Read specific properties directly:
element.addEventListener('pointerdown', e => {
console.log('id:', e.pointerId, 'x:', e.clientX, 'y:', e.clientY, 'type:', e.pointerType, 'pressure:', e.pressure);
});
- If you want a JSON-ish snapshot of useful fields:
element.addEventListener('pointerdown', e => {
console.log(JSON.stringify({
pointerId: e.pointerId,
clientX: e.clientX,
clientY: e.clientY,
pointerType: e.pointerType,
pressure: e.pressure
}));
});
- To enumerate available property names (including prototype names):
element.addEventListener('pointerdown', e => {
console.log(Object.getOwnPropertyNames(e)); // own properties
console.log(Object.getOwnPropertyNames(Object.getPrototypeOf(e))); // prototype properties
});
๐ก Explanation
- When a JavaScript object is coerced to a string (for example via
alert()or string concatenation), the runtime calls itstoString()behavior, which for DOM events produces"[object PointerEvent]". - DevTools
console.log(event)shows an interactive object you can expand to inspect properties.console.dir(event)gives a clearer property view. - A PointerEvent is the unified DOM event type for mouse, touch, and pen input; it exposes properties such as
pointerId, coordinates (clientX,clientY),pointerType("mouse","touch","pen"),pressure,tiltX, andtiltY.
๐ Key Points
[object PointerEvent]= stringified PointerEvent, not an error.- Use
console.log(event)orconsole.dir(event)to inspect the object in DevTools. - Read properties like
pointerId,clientX,clientY,pointerType,pressureto get useful data. - To serialize, pick the fields you need (e.g., via
JSON.stringify({...})) because the event object itself may not be directly serializable.