Given a pixel position on a webpage, say x = 40 and y = 100, is there a way to invoke the "Inspect Element" option from Chrome dev tools on this pixel programmatically? Can puppeteer do it or some other way?
-
This is _not_ opening Chrome dev tools, but getting the element at x, y using plain JavaScript: `document.elementFromPoint(x, y);` https://stackoverflow.com/questions/1259585/get-element-at-specified-position-javascript – Wumms Nov 06 '18 at 22:08
-
@Wumms I think you identified correctly the issue in my question. If I could get the element at (x, y) with elementFromPoint() then I could do whatever analysis on it that I wanted. – J. Cool Nov 06 '18 at 23:43
2 Answers
As a general answer there is no way to do this currently.
per the Chromium issues page
"We only allow explicit devtools opening."
This means that you must manually open the inspector through either keyboard shortcut or menu selection.
Note The way around this is to use a macro service of some kind that can emit keyboard events(such as ctrl+shift+j
) and mouse clicks(to right click and click inspect element
). however, it is still a manual process in reality. Everything that can be done on a computer can be turned into a macro on some level, so it's a bit out of scope to explain how to do this.

- 8,474
- 1
- 22
- 34
-
Thanks @zfrisch. Sounds like I'll have to setup up some higher level macro to setup the mouse cursor at some point (x, y). – J. Cool Nov 07 '18 at 16:31
So I think I found the answer to my question. I should've instead asked if there was a programmatic way to get HTML element at pixel position (x, y), to which @Wumm's comment above answers it. You can use elementFromPoint(x, y) to get HTML element.
Secondly, the answer to the way I posed my question is answered by @zfrisch. So there is no automatic way to invoke Devtools themselves.

- 75
- 3
- 7