Skip to content

Mouse click coordinates incorrect in editor iframe — clicks register in wrong grid cell #8716

@VDotOnDaDot

Description

@VDotOnDaDot

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • p5.strands
  • WebGL
  • DevOps, Build process, Unit testing
  • Internationalization (i18n)
  • Friendly Errors
  • Other (specify if possible)

p5.js version

1.11.13

Web browser and version

Google Chrome - 146.0.7680.178

Operating system

Windows 11and iOS 26

Steps to reproduce this

Mouse click coordinates appear to be offset or misaligned when running sketches in the p5.js web editor, causing clicks to register in the wrong position relative to what is drawn on the canvas. Hover/mouseover behavior works correctly (suggesting mouseX/mouseY are correct for continuous tracking), but discrete click events (mousePressed) appear to calculate grid cell positions incorrectly.
Steps to reproduce:

Open any sketch in the p5.js web editor that uses a grid or tile system where clicking a specific cell triggers logic
Click a cell that is more than 1 unit away from the origin or from another recently clicked cell
The click registers in the wrong cell or is ignored entirely

Expected behavior:
Clicks should register in the same position that hover/draw coordinates indicate, consistent with running the same sketch on OpenProcessing.org or a local server.
Actual behavior:
Clicks appear offset — nearby targets (1 cell away) sometimes work, but targets further away consistently fail. The sketch works correctly on OpenProcessing.org with identical code and p5.js version, confirming the issue is specific to the web editor's iframe environment.
Environment:

Browser: Chrome (also tested in incognito mode — issue persists)
OS: [add your OS here]
p5.js web editor version: [check the editor's about page or footer]
p5.js library version: [check your sketch's index.html or the editor's default]
Device: Tested on both desktop computer and mobile phone — issue present on both
Network: Tested on WiFi, mobile data, and VPN — issue persists across all

Additional context:

The issue began appearing without any code changes
An older version of the same sketch that previously worked correctly also exhibits the issue
The issue appeared after physically changing location (different network region), suggesting a possible CDN or server-side caching issue serving a different version of the editor
Switching to OpenProcessing.org with identical code resolves the issue completely
pixelDensity(1) in setup() does not fix the issue
Browser cache clearing does not fix the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions