Bug 274773 - env(safe-area-inset-*) always returns 0
Summary: env(safe-area-inset-*) always returns 0
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: Safari 17
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2024-05-28 04:46 PDT by Ben Frain
Modified: 2024-06-04 04:47 PDT (History)
5 users (show)

See Also:


Attachments
reduction of the safe area reading technique (1.58 KB, text/html)
2024-05-28 04:46 PDT, Ben Frain
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Frain 2024-05-28 04:46:24 PDT
Created attachment 471525 [details]
reduction of the safe area reading technique

For the longest time it has been possible to get the value or the iOS safe areas using the following technique:

```css
:root {
    --sat: env(safe-area-inset-top);
    --sar: env(safe-area-inset-right);
    --sab: env(safe-area-inset-bottom);
    --sal: env(safe-area-inset-left);
}
```

And then read that value with JS:

```js
getComputedStyle(document.documentElement).getPropertyValue("--sat")
```

However this no longer works. I have tried adding this behind a timeout of 5s but it remains at zero. Attachment is a reduction of the technique.

The environment variable should resolve to the safe area inset value.
Comment 1 Alexey Proskuryakov 2024-05-28 09:36:58 PDT
Thank you for the report. Could you please specify your exact iOS version, and also provide detailed steps to reproduce?

Notably, I cannot reproduce this in landscape orientation on iPhone 15 Pro, but I have a newer WebKit build. It is AFAICT expected to get zeroes in portrait orientation.
Comment 2 Ben Frain 2024-05-28 10:49:12 PDT
Hi Alex, 17.5.1. 

But yes, I was expecting a value back in portrait, as there used to be in prior versions. 

Could you clarify why this now returns 0px? How do we account for the dynamic island area etc in JS?

Are there any recents posts/docs on the WebKit blog that explain the newer behaviour?

Thanks, Ben
Comment 3 Alexey Proskuryakov 2024-05-28 14:05:59 PDT
What makes me say it is that there are no scroll bars or anything else to avoid in this test case. Maybe a test case with more content and scrolling also gets 0, and that's more obviously an issue?

I'm not an expert on this feature, hopefully one of the folks I CC'ed can chime in with a deeper answer.
Comment 4 Radar WebKit Bug Importer 2024-06-04 04:47:14 PDT
<rdar://problem/129213964>