[Web API type definition issue] `Element.requestFullscreen` should be optional
Summary
typeof document.documentElement.requestFullscreen is undefined in iOS Safari
Expected vs. Actual Behavior
typeof document.documentElement.requestFullscreen
Expected: not defined in iOS 26.0.1 Safari (and probably in the webview) Actual: always a function
Playground Link
No response
Browser Support
- [x] This API is supported in at least two major browser engines (not two Chromium-based browsers).
Have Tried The Latest Releases
- [x] This issue applies to the latest release of TypeScript.
- [x] This issue applies to the latest release of
@types/web.
Additional Context
Suggested change will enforce optional chaining for safer runtime code.
document.documentElement.requestFullscreen?.()
It's only undefined because Safari doesn't implement it yet: https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullscreen
We don't generally make everything potentially undefined because one browser is lagging behind. If two engines have the feature, then we include the type.
I do understand that iOS Safari is the only one lagging behind, but is Apple even willing to implement it?
I would love to know a way to config it as optional — I wasn't doing QA with iPhones, and I've had to fix mistakes in bulk with a string search.
What version of iOS Safari are we talking about? Per the WebKit IDL it should be available everywhere. 🤔
@saschanaz all versions of iOS Safari including the latest 26.
Personal test results:
[email protected]:
undefined[email protected]:function
https://caniuse.com/fullscreen
Only available on iPad, not on iPhone. Shows an overlay button which can not be disabled. Swiping down exits fullscreen mode, making it unsuitable for some use cases like games.
https://github.com/mdn/browser-compat-data/blob/88673dfeb94aa588d96baf90dbc8742538d78d12/api/Element.json#L4805-L4813
The source of truth is the WebKit source code, everything else is an observed result. 🤔
I guess iOS doesn't have webkitRequestFullScreen either?
fwiw, you can use https://mdn-bcd-collector.gooborg.com/ (the same thing that MDN uses to gather the data)
These are the tests I've ran. Is there a webkit prefixed version that I am supposed to run?
api.Element.requestFullscreen
api.Element.requestFullscreen.returns_promise