Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/busy-icons-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Defer `onEnterPiP` visibility update until after the next microtask and animation frame so Document Picture-in-Picture embedders can append DOM into the PiP window before `isElementInPiP` runs.
10 changes: 8 additions & 2 deletions src/room/track/RemoteVideoTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,14 @@ class HTMLElementInfo implements ElementInfo {

private onEnterPiP = () => {
window.documentPictureInPicture?.window?.addEventListener('pagehide', this.onLeavePiP);
this.isPiP = isElementInPiP(this.element);
this.handleVisibilityChanged?.();
// Document PiP: the browser may fire 'enter' before the app has appended its subtree into
// documentPictureInPicture.window. Defer so pipWin.document.contains(video) is reliable.
queueMicrotask(() => {
requestAnimationFrame(() => {
this.isPiP = isElementInPiP(this.element);
this.handleVisibilityChanged?.();
});
});
};

private onLeavePiP = () => {
Expand Down
Loading