electron / electron/electron

[Feature Request]: Add webFrame.x, webFrame.y coordinates relative to the BrowserWindow

Open
#32,250 0 comments 0 reactions 0 assignees View on GitHub
enhancement :sparkles:
Dominant language
C++
Stars
123k
Forks
17.5k
Avg merge
14h 22m
Merged PRs (30d)
873

Description

### Preflight Checklist

- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a feature request that matches the one I want to file, without success.

### Problem Description

I want to get a subframe position relative to the BrowserWindow or BrowserView, no matter the nesting level. I'm building a browser-like application and require this to make an "Inspect element" contextmenu option work (in the contextmenu event, I only get the coordinates relative to the iframe, but I need coordinates relative to the top frame - the webContents).

Separately, I need to get webContents (top frame) position relative to its BrowserView or BrowserWindow when devTools are attached on the left https://github.com/electron/electron/issues/32131

### Proposed Solution

Add `x` and `y` property to a `WebFrame` instance that would indicate frame's position relative to the window that contains them. It should work both for the top frame and any subframe.

### Alternatives Considered

For now I wanted to make it work at least for iframes that are direct descendants of the top frame by getting the iframe position from the top frame. However I'm stopped by: https://github.com/electron/electron/issues/32249

And even if the above was possible, making this work for nested iframes would be very complex and require `nesting_level * 2` (or 4 if main process needs to be used for routing) number of IPC calls to compute it and probably affect performance.

### Additional Information

- It does not matter if it's relative to BrowserView or BrowserWindow since the position of BrowserView relative to the BrowserWindow is always known. Whatever is easier and makes more sense (probably BrowserWindow).

- Implementing this would partially solve another feature request: https://github.com/electron/electron/issues/32131

- I have no idea how complex it is. Supporting many nested levels would be nice to have, but not a must. At the very least I need to know the position of the top frame relative to the window (https://github.com/electron/electron/issues/32131) and be able to locate an iframe in DOM by routing id https://github.com/electron/electron/issues/32249 (so I can create my workaround for direct descendants) I just thought that maybe if it's not something super complex this would be a more elegant solution that would cover both the problem with devTools on the left and the iframe positions

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.