Skip to content

screen{X,Y,Left,Top} use window location, not viewport - #45097

Merged
Josh-Cena merged 4 commits into
mdn:mainfrom
eeminionn:agent/issue-45048-no-browser-implements-screenx-screen-31557916210
Sep 2, 2026
Merged

screen{X,Y,Left,Top} use window location, not viewport#45097
Josh-Cena merged 4 commits into
mdn:mainfrom
eeminionn:agent/issue-45048-no-browser-implements-screenx-screen-31557916210

Conversation

@eeminionn

Copy link
Copy Markdown
Contributor

Summary

Addresses #45048: No Browser Implements screenX, screenY according to the spec

Changed files

  • files/en-us/web/api/window/screenx/index.md

Validation

  • git diff --check: passed

Fixes #45048

@eeminionn
eeminionn requested a review from a team as a code owner August 12, 2026 02:49
@eeminionn
eeminionn requested review from wbamberg and a lite review from Copilot and removed request for a team August 12, 2026 02:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added Content:WebAPI Web API docs size/xs [PR only] 0-5 LoC changed labels Aug 12, 2026
@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Preview URLs (5 pages)

Flaws (2)

Note! 4 documents with no flaws that don't need to be listed. 🎉

Found an unexpected or unresolvable flaw? Please report it here.

URL: /en-US/docs/Web/API/Window
Title: Window
Flaw count: 2

  • macros:
    • Macro domxref produces link /en-US/docs/Web/API/HTMLElement/invalid_event which is a redirect
    • Macro domxref produces link /en-US/docs/Web/API/Element/select_event which is a redirect
External URLs (3)

URL: /en-US/docs/Web/API/Window/screenLeft
Title: Window: screenLeft property


URL: /en-US/docs/Web/API/Window/screenTop
Title: Window: screenTop property


URL: /en-US/docs/Web/API/Window/screenX
Title: Window: screenX property

(comment last updated: 2026-09-02 01:05:23)

@Josh-Cena

Copy link
Copy Markdown
Member

cc @greggman

@greggman

Copy link
Copy Markdown
Contributor

lgtm. FYI screenY has the same issue with showing and hiding things like bookmark bars.

@Josh-Cena

Copy link
Copy Markdown
Member

Wait—@greggman do you know where in the spec does it say this property is based on the content (viewport, I assume)? The spec says:

The screenX and screenLeft attributes must return the x-coordinate, relative to the origin of the Web-exposed screen area, of the left of the client window as number of CSS pixels, or zero if there is no such thing.

Weirdly, it never gave a definition for client window; but its only other appearance is in outerHeight/outerWidth, which is already documented on MDN as including the browser UI.

So perhaps this is just a content bug, and we should replace everything that says "viewport" (which means innerWidth) to "window" (which means outerWidth)?

@greggman

Copy link
Copy Markdown
Contributor

maybe. It's a pretty ridiculous API. It had a purpose. Browsers apparently broke it and never bothered to make it useful again. I'd suggest removing the sample since it doesn't actually work.

@Josh-Cena

Josh-Cena commented Sep 2, 2026

Copy link
Copy Markdown
Member

idk, it looks pretty useful to me 🤷 This example also works for me. The circle moves as you drag the browser window across the device screen. Sure, it's offset by showing/hiding toolbars/sidebars, but I don't think that subtracts from its usefulness in most cases.

@Josh-Cena Josh-Cena changed the title docs: No Browser Implements screenX, screenY according to the spec screen{X,Y,Left,Top} use window location, not viewport Sep 2, 2026
@github-actions github-actions Bot added size/m [PR only] 51-500 LoC changed and removed size/xs [PR only] 0-5 LoC changed labels Sep 2, 2026
@Josh-Cena

Copy link
Copy Markdown
Member

There's a bug in this demo that prevents the correct screenLeft screenTop from being read if the screen initially starts with screenLeft=0. I'll fix that.

@greggman

greggman commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

I’m curious what you think the use case is? To me the use case is to align with something relative to the screen. The center or one of the edges. It does’t work for that. Worse, if you’re a vertical tab user and you have the auto hide feature (common), it breaks even more

@Josh-Cena

Copy link
Copy Markdown
Member

mdn/dom-examples#393 should fix the bug in the demo.

@Josh-Cena

Copy link
Copy Markdown
Member

I’m curious what you think the use case is? To me the use case is to align with something relative to the screen. The center or one of the edges. It does’t work for that. Worse, if you’re a vertical tab user and you have the auto hide feature (common), it breaks even more

Well I can't speak for vertical tabs. But there's only an unobservable dimension change if the browser chrome dynamically changes. In the remaining cases, this demo works as intended.

MDN is not in a good position to discuss whether a feature is "useful" anyway; we can only document what it does and you as a reader can figure out whether it fits your particular use case. If you think there's an unimplementable UX involving dynamic browser UI, you could raise the issue with CSSWG to have additional ways to measure, say, the viewport's position within the window. That would definitely be helpful for this demo, which, per the note I added, suffers exactly from this lack.

@Josh-Cena
Josh-Cena merged commit 6b9bb94 into mdn:main Sep 2, 2026
9 checks passed
@greggman

greggman commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

that is not really my point though. The demo does not do what it claims to do

What it claims to do

In this example we are using Window.screenLeft/Window.screenTop plus Window.requestAnimationFrame() to constantly redraw the circle in the same physical position on the screen

It does not keep the circle in the same physical position on the screen. And further, every browser puts the circle in a different place.

chrome

Screen.Recording.2026-09-02.at.12.41.01.mp4

firefox

Screen.Recording.2026-09-02.at.12.43.28.mp4

safari

Screen.Recording.2026-09-02.at.12.44.09.mp4

@Josh-Cena

Copy link
Copy Markdown
Member

Yes, as I said, no behavior can be said about when the browser UI changes dynamically. I already added the following disclaimer:

This example compensates for changes in the browser window's position, but not for changes in the viewport's position within the window. Showing or hiding a toolbar or sidebar can therefore shift the circle on the screen.

This demo is only for when the browser UI stays constant. As I also said, I believe true fixed screen position is unattainable unless you can query the viewport's location within the window, and if that's what you'd like to see, it would be very helpful to ask in CSSWG.

@greggman

greggman commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

no behavior can be said about when the browser UI changes dynamically

Even if the UI doesn't change dynamically. Set one window to have its tabs visible and another not. Then run such a demo in 2 windows. The 2 windows will not align.

They used to, example from 2011 (video is newer, demo was written in 2011)

https://www.youtube.com/watch?v=ef20wKxt5aY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No Browser Implements screenX, screenY according to the spec

5 participants