Return to inline video when switching back to tab#41
Conversation
Reviewer's GuideAdds logic to detect and correct Safari/YouTube’s undesirable PiP-to-fullscreen transition when disabling PiP, ensuring the video returns to inline mode instead of staying fullscreen when returning to the tab. Sequence diagram for PiP disable and fullscreen correctionsequenceDiagram
actor User
participant AutoPiPExtension as AutoPiP
participant VideoElement as video
participant SafariYouTube as Safari_YouTube
User->>AutoPiPExtension: disablePiP()
AutoPiPExtension->>AutoPiPExtension: lastPiPDisableTime = Date.now()
AutoPiPExtension->>VideoElement: setWebkitPresentationMode(video, inline)
SafariYouTube-->>VideoElement: webkitPresentationMode = fullscreen
SafariYouTube-->>AutoPiPExtension: webkitpresentationmodechanged(event)
AutoPiPExtension->>AutoPiPExtension: [Date.now() - lastPiPDisableTime < FULLSCREEN_CORRECTION_WINDOW_MS]
AutoPiPExtension->>VideoElement: forceInlinePresentation(video)
VideoElement->>SafariYouTube: document.exitFullscreen()
VideoElement->>SafariYouTube: video.webkitExitFullscreen()
VideoElement->>SafariYouTube: setWebkitPresentationMode(video, inline)
AutoPiPExtension->>VideoElement: setTimeout(300ms)
AutoPiPExtension->>VideoElement: forceInlinePresentation(video) [if still fullscreen]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The time-based heuristic (FULLSCREEN_CORRECTION_WINDOW_MS) may incorrectly force inline when the user intentionally enters fullscreen shortly after exiting PiP; consider tracking a specific "PiP exit in progress" flag or correlating the event to the exact video instead of using a global time window.
- In the safety-net timeout, exiting
document.fullscreenElementwill also affect unrelated fullscreen elements; it would be safer to ensure the fullscreen element corresponds to the target video/player before callingdocument.exitFullscreen().
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The time-based heuristic (FULLSCREEN_CORRECTION_WINDOW_MS) may incorrectly force inline when the user intentionally enters fullscreen shortly after exiting PiP; consider tracking a specific "PiP exit in progress" flag or correlating the event to the exact video instead of using a global time window.
- In the safety-net timeout, exiting `document.fullscreenElement` will also affect unrelated fullscreen elements; it would be safer to ensure the fullscreen element corresponds to the target video/player before calling `document.exitFullscreen()`.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Hi @piekay, Cheers, |
|
I have never seen this player in my life lol |
|
Ok, so after a bunch of testing I figured out what exactly caused this. So when you use Safaris built-in PIP player option it opens this player. If you now end this and continue playing Videos on Youtube Safari still "remembers" that you used the PIP mode, so if the extension is used on a Tab where a single Youtube Video was played with the inbuilt Video player (which is what I did) and then switch back, it gets stuck in the player window, since it wasn't coded with this scenario in mind. |

I noticed that when leaving Youtube, switching to another page, then returning to Youtube causes the video to continue playing in full screen. This small addition should fix that.
Written with the help of AI - Tested by hand
Summary by Sourcery
Ensure videos return to inline mode instead of remaining fullscreen when exiting Picture-in-Picture and returning to the tab, particularly for Safari/YouTube.
Bug Fixes: