Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 412a8234329f8c748aadc6e99062aabf1700c84b
https://github.com/WebKit/WebKit/commit/412a8234329f8c748aadc6e99062aabf1700c84b
Author: Sihui Liu <[email protected]>
Date: 2026-06-10 (Wed, 10 Jun 2026)
Changed paths:
M Source/WebCore/html/HTMLMediaElement.cpp
M Source/WebCore/html/HTMLMediaElement.h
A Tools/TestWebKitAPI/Resources/cocoa/autoplay-quirk-pause-fires-once.html
M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WebsitePolicies.mm
Log Message:
-----------
Prevent re-entrant calls to dispatchPlayPauseEventsIfNeedsQuirks()
https://bugs.webkit.org/show_bug.cgi?id=316746
rdar://179191475
Reviewed by Ryosuke Niwa.
dispatchPlayPauseEventsIfNeedsQuirks() dispatches synthesized `playing` and
`pause` events to satisfy sites whose JS
player state machines rely on these events to detect that autoplay was
prevented (SynthesizedPauseEvents), or to
recover after being restored from the back/forward cache (rdar://68938833).
The function was not re-entrant-safe because a common JS pattern is to call
video.play() from a `pause` event handler to
retry playback. When autoplay was blocked, the sequence was:
1. setAutoplayEventPlaybackState(PreventedAutoplay) =>
dispatchPlayPauseEventsIfNeedsQuirks() // schedule playing +
pause events
2. `pause` event fires, JS handler calls video.play() // autoplay blocked again
3. setAutoplayEventPlaybackState(PreventedAutoplay) =>
dispatchPlayPauseEventsIfNeedsQuirks() // schedule playing +
pause events again, and cause infinite loop
This can produce hundreds of log entries per millisecond and could trigger
logd's per-process quarantine on affected
pages. To fix this, this patch adds a bool guard
m_isDispatchingAutoplayPlayPauseQuirkEvents and consolidates two
scheduleEvent() calls into a single queued task that ispatches both events
synchronously via dispatchEvent(). A
SetForScope sets the guard for the duration of the task, covering the entire JS
execution window. Any re-entrant call to
dispatchPlayPauseEventsIfNeedsQuirks() during that window — whether from the
`playing` or the `pause` handler — returns
immediately.
API Test: WebpagePreferences.WebsitePoliciesSynthesizedPauseEventFiresOnce
* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::dispatchPlayPauseEventsIfNeedsQuirks):
* Source/WebCore/html/HTMLMediaElement.h:
* Tools/TestWebKitAPI/Resources/cocoa/autoplay-quirk-pause-fires-once.html:
Added.
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WebsitePolicies.mm:
(TEST(WebpagePreferences, WebsitePoliciesSynthesizedPauseEventFiresOnce)):
Canonical link: https://commits.webkit.org/314984@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications