跪拜 Guibai
← Back to the summary

AI Code Sailed Through Chrome, Then Broke Safari: The Four WebKit Traps That Nearly Cost a Dev Their Job

Last Friday afternoon, looking at the screenshot from the test engineer on WeChat Work, cold sweat ran down my back.

The screenshot was a screen recording sent by a client: our just-launched marketing campaign page ran as smoothly as chocolate on Chrome and Edge, but on iOS Safari, the page froze, white-screened, and a bottom modal kept bouncing up and down like a ghost, even completely unresponsive to clicks.

I stared at the screen and typed with trembling hands: "Can you try Chrome?" The client replied: "I only use Apple."

At that moment, the soul-searching question from Juejin's trending list flashed through my mind: Why does the same piece of code always have bugs on Safari?

Even worse, this time the code was generated in one go by Cursor with Claude 3.5. It ran flawlessly in the local Chrome environment, all tests green. I even thought I'd found a shortcut to full-stack development.

Reality slapped me hard: AI can write logically correct code, but AI doesn't understand how anti-human Safari is.

1. Peeling back the AI code's underwear, I found four 'Safari killers'

To solve this P0-level production incident, I stayed up until 2 AM. Looking back at the AI-generated code, the logic was all correct, but in the face of Safari's WebKit engine, landmines were everywhere.

Landmine 1: The classic new Date()

When AI writes date handling, it often uses:

const date = new Date('2026-11-17 10:00:00');

In Chrome, this is fine. But in Safari, it directly returns Invalid Date.

Why? Because Safari strictly follows the ECMAScript spec and does not support date strings with spaces. You have to write 2026/11/17 10:00:00 or the standard ISO format 2026-11-17T10:00:00.

Because of that tiny hyphen, all the countdown timers and date formatting on the page crashed, white-screening the whole page.

Landmine 2: You thought 100vh equals screen height?

To make the page fill the screen, AI added height: 100vh for me.

In Chrome it's perfect. In Safari, the address bar and bottom toolbar dynamically collapse. 100vh calculates the maximum height, so the bottom content gets covered by the system toolbar, or causes a weird double scrollbar.

Solution: Replace all 100vh with 100dvh (dynamic viewport height). By 2026, compatibility is already excellent, but AI still writes according to the old habits of 2021.

Landmine 3: The ghostly rubber-band effect

The client said "the modal is shaking crazily," because I wrote a position: fixed drawer with overflow-y: auto.

In Safari, when you scroll to the top or bottom and keep pulling, it triggers the "rubber-band bounce" effect. If the outer layer isn't locked properly, the inner fixed element will bounce up and down with it, looking like it has Parkinson's.

Solution:

body {
  overscroll-behavior-y: none;
}

This prevents the chain reaction of overscrolling.

Landmine 4: The elusive -webkit- prefix

AI wrote a cool text truncation for me:

display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;

It didn't forget that one, but when trying the newest features (like the backdrop-filter frosted glass effect), if you miss the -webkit- prefix, Safari simply doesn't render it, and your modal background becomes a layer of black plastic.

2. The cruel truth of the AI era: code becomes cheap, but 'fallback' becomes expensive

After this accident, I'm completely sober.

In the past, we wrote code "search-engine oriented," searching StackOverflow when we hit a pit. Now, we're "AI-oriented programming," asking Claude when we hit a pit: "Why doesn't this code work in Safari?"

But have you noticed? The default context of AI-generated code is always the ideal state.

It doesn't know how picky Apple users are about experience, it doesn't know what mischief the WeChat built-in browser (also WebKit-based) can cause, and it doesn't know how much animation your product manager added just to keep users on the phone for two more seconds.

It can write a complex Redux state management in ten minutes, but it will never test for you: when Safari's bottom toolbar pops up, will the popup driven by that state management be blocked?

It's like AI built you a beautifully decorated house, but it forgot the foundation, forgot the waterproofing, and forgot to add rebar in the load-bearing walls.

When the storm (real-device environment) comes, the house collapses, and the owner doesn't go after AI; they come after you.

3. Under Safari's claws, how should front-end developers save themselves?

If you also use AI to assist in writing code, remember the following points, and don't let Safari teach you a lesson:

  1. Don't be fooled by all-green tests. In your CI pipeline, make sure to include Playwright or Cypress WebKit engine tests. Even just running the core main flow can block 80% of low-level compatibility errors.
  2. Your test devices must include an iPhone. Don't fool yourself with the "iPhone simulation" in Chrome DevTools. On a real device, even the respiration of Safari is different from what you imagine.
  3. Beware of the 'black magic' AI gives you. AI likes to use extremely "unorthodox" CSS to achieve cool effects, and if Safari doesn't support it, the whole page is ruined. For complex layouts, rather be safe with native flex or even float than use the newest syntax.
  4. Make good use of @supports. If you must use new features, always do capability detection:
@supports (-webkit-touch-callout: none) {
  /* Safari-specific hell */
}

In Conclusion

After fixing the bug and committing the code, I quietly typed a line in the commit message: fix: Safari compatibility for AI generated code (again).

That night when I got home, I continued writing my own side project with Cursor. It's really nice, indeed nice; the code it writes is better and faster than mine. But now I always do one extra action: refresh in Safari, click every button, and pull the page.

AI lets me stop being a ruthless "typewriter," but it doesn't strip away the bottom line of being a front-end engineer.

Code can be generated automatically, but production incidents can only be shouldered by you.

Comments

Top 2 from juejin.cn, machine-translated. The original thread is authoritative.

组合搭配函数

Running it on a real device is the one step that matters too much—having everything green on your computer means nothing. I got burned by that date format too; it went white-screen in production, and in the end I had to own the blame myself. That stings.

咬代码的兽

Cross-browser compatibility in AI-written code really is a disaster zone; Safari's support for new CSS features has always been half a step behind. My habit is to go through a caniuse checklist before submitting for testing. Articles about these kinds of pitfalls are aggregated quite a lot on ai345—searching by scenario is pretty convenient.