Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document.elementFromPoint not implemented #1435

Open
dsathyakumar opened this issue Apr 1, 2016 · 7 comments
Open

document.elementFromPoint not implemented #1435

dsathyakumar opened this issue Apr 1, 2016 · 7 comments
Labels
feature layout Blocked on implementing a layout engine

Comments

@dsathyakumar
Copy link

TypeError: Object [object HTMLDocument] has no method 'elementFromPoint'

document.elementFromPoint is not implemented by jsdom. Raising it as an issue cos it was raised elsewhere inikulin/parse5#50

@inikulin
Copy link
Contributor

inikulin commented Apr 1, 2016

It's impossible to implement it in jsdom currently, because it requires layouting.

@quantizor
Copy link

It could at least be stubbed, though.

@Sebmaster
Copy link
Member

In that case feature detection wouldn't work anymore - you can also easily stub it in the created callback.

@dsathyakumar
Copy link
Author

I'm working on a library (built with Node on server side) that conducts accessibility (A11y) audits on HTML, for which one of the utils has code to check if an element is offscreen, in scrollable area, outside the viewport and various such stuff.

document.elementFromPoint was an easy way to calculate it. The issue began when I started writing server side test cases for the utils, via JSDOM. It wasn't supporting it.

@quantizor
Copy link

Yeah that will realistically never work in JSDOM. No layout engine = no screen, no scrolling, etc.

For your needs I'd recommend something like phantom.

@domenic domenic added the feature label Jul 2, 2016
@Zirro Zirro added the layout Blocked on implementing a layout engine label May 27, 2018
@gkarapeev
Copy link

gkarapeev commented Mar 10, 2022

It's interesting why some angular unit tests in my repo have been passing with jest 22. They test code which uses this method. Now with jest 27, I hit this issue.

@alexreardon
Copy link

It is unfortunate today that using document.elementFromPoint causes an error given that document.elementFromPoint is an old and stable API.

I propose that document.elementFromPoint be added to jsdom, and that the function would just return null, as null is a valid return of the function. Making this change would mean that calls to document.elementFromPoint would no longer error

document.elementFromPoint(x: number, y: number): Element | null

Implementation:

document.elementFromPoint = function elementFromPoint() {
    return null;
  }

I am happy to raise a pull request @domenic if it is helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature layout Blocked on implementing a layout engine
Projects
None yet
Development

No branches or pull requests

8 participants