| Summary: | A black screen appears in a muted video element outside the viewport | ||||||
|---|---|---|---|---|---|---|---|
| Product: | WebKit | Reporter: | Kyu Simm <simmkyu> | ||||
| Component: | Media | Assignee: | youenn fablet <youennf> | ||||
| Status: | RESOLVED FIXED | ||||||
| Severity: | Normal | CC: | devalevenkatesh, eric.carlson, jer.noble, simmkyu, webkit-bug-importer, youennf | ||||
| Priority: | P2 | Keywords: | InRadar | ||||
| Version: | Other | ||||||
| Hardware: | Other | ||||||
| OS: | Other | ||||||
| Attachments: |
|
||||||
|
Description
Kyu Simm
2022-05-31 13:48:12 PDT
Pull request: https://github.com/WebKit/WebKit/pull/1575 Uploaded PR should fix this. One workaround is to not set srcObject within a user gesture but use a setTimeout so that we do not remove the invisible autoplay restriction. Or to actually set srcObject as part of user gesture if the video element is visible. Committed r295591 (251596@main): <https://commits.webkit.org/251596@main> Reviewed commits have been landed. Closing PR #1575 and removing active labels. This is marked as fixed but the issue is still not resolved. iOS 15.6 Safari macOS 12.4 Safari 15.5 We had added a workaround for this which is now running into a AbortError. The workaround was: ``` // In Safari, a hidden video element can show a black screen. // See https://bugs.webkit.org/show_bug.cgi?id=241152 for more information. if (new DefaultBrowserBehavior().requiresVideoPlayWorkaround() && videoElement.paused) { videoElement.play(); } ``` The codepath runs on a user gesture which is a button click from user. The videoElement.play() is running into the AbortError. Detailed Error: [Error] Fatal error: this was going to be caught, but should not have been thrown. – AbortError: The operation was aborted. AbortError: The operation was aborted. fatal (Prod:2:986193) fatal (anonymous function) (Prod:2:985999) [Log] [DEMO] AbortError: The operation was aborted. (Prod, line 2) [Error] Unhandled Promise Rejection: AbortError: The operation was aborted. (anonymous function) rejectPromise If I comment out the `videoElement.play()` then the AbortError goes away but then the existing black screen issue still exists. Per suggestion, I tried wrapping the srcObject setting inside a IntersectionObserver, but still get the AbortError: const callback: IntersectionObserverCallback = (entries: IntersectionObserverEntry[]) => { if(entries[0].isIntersecting) { if (videoElement.srcObject !== videoStream) { videoElement.srcObject = videoStream; // In Safari, a hidden video element can show a black screen. // See https://bugs.webkit.org/show_bug.cgi?id=241152 for more information. if (new DefaultBrowserBehavior().requiresVideoPlayWorkaround() && videoElement.paused) { videoElement.play(); } } } }; if (!!window.IntersectionObserver) { const observer = new IntersectionObserver(callback); observer.observe(videoElement); } Should I be re-opening this bug? |