Skip to content

Instantly share code, notes, and snippets.

@mbforbes
Created March 8, 2025 20:22
Show Gist options
  • Save mbforbes/9b91a9a7ebaefa020e897a0f9a4ad41e to your computer and use it in GitHub Desktop.
Save mbforbes/9b91a9a7ebaefa020e897a0f9a4ad41e to your computer and use it in GitHub Desktop.
Dump touch event
function dumpTouchEvent(event: TouchEvent): string {
// Start with the basics
const result = {
type: event.type,
timeStamp: event.timeStamp,
isTrusted: event.isTrusted,
bubbles: event.bubbles,
cancelable: event.cancelable,
defaultPrevented: event.defaultPrevented,
eventPhase: event.eventPhase,
};
// Handle touches, targetTouches, and changedTouches
['touches', 'targetTouches', 'changedTouches'].forEach((touchListName) => {
if (event[touchListName]) {
result[touchListName] = [];
for (let i = 0; i < event[touchListName].length; i++) {
const touch = event[touchListName][i];
result[touchListName].push({
identifier: touch.identifier,
screenX: touch.screenX,
screenY: touch.screenY,
clientX: touch.clientX,
clientY: touch.clientY,
pageX: touch.pageX,
pageY: touch.pageY,
radiusX: touch.radiusX,
radiusY: touch.radiusY,
rotationAngle: touch.rotationAngle,
force: touch.force,
});
}
}
});
return JSON.stringify(result, null, 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment