Skip to content

Return to inline video when switching back to tab#41

Open
piekay wants to merge 1 commit into
vordenken:feature/v2.1.0from
piekay:feature/return-on-switch-back
Open

Return to inline video when switching back to tab#41
piekay wants to merge 1 commit into
vordenken:feature/v2.1.0from
piekay:feature/return-on-switch-back

Conversation

@piekay

@piekay piekay commented Jul 17, 2026

Copy link
Copy Markdown

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:

  • Detect and correct unwanted transitions from PiP to fullscreen presentation mode that occur when exiting PiP on Safari/YouTube.
  • Add a fallback check to force videos out of fullscreen shortly after PiP exit if the player remains stuck in fullscreen.

@sourcery-ai

sourcery-ai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds 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 correction

sequenceDiagram
    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]
Loading

File-Level Changes

Change Details Files
Track the timing of PiP disable operations and correct unwanted transitions from PiP to fullscreen via presentation mode change events.
  • Introduce a global timestamp variable and a correction window constant to record recent PiP disable operations.
  • Add a webkitpresentationmodechanged capture-phase listener that detects fullscreen transitions occurring shortly after PiP is disabled and forces the video back to inline presentation.
  • Implement a forceInlinePresentation helper that exits both document-level and legacy webkit video fullscreen and sets the presentation mode back to inline, with debug logging and error handling.
AutoPiP Extension/Resources/content.js
Integrate fullscreen correction into the PiP disable flow with a secondary safety check after the main inline transition request.
  • Update disablePiP to store the timestamp of the PiP disable request before changing presentation mode.
  • Add a post-disable timeout that checks for lingering fullscreen or document fullscreen state and restores inline presentation if necessary, with debug logging.
  • Keep existing PiP presence checks and error handling intact while layering the new correction logic on top.
AutoPiP Extension/Resources/content.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d412f7bb-703a-47a6-9efb-4621d59edcfd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.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().
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()`.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@vordenken

Copy link
Copy Markdown
Owner

Hi @piekay,
thanks for the contribution! But could you maybe explain a bit more (or make a video?) what exactly this fixes? I don't quite understand the issue here.

Cheers,
VD

@piekay

piekay commented Jul 18, 2026

Copy link
Copy Markdown
Author
image

When I switched back to the video I sometimes got this hovering video player when switching back. If I got it I could reliably reproduce it for said video. With the patch it always returns directly to the video playing in the YouTube website itself

@vordenken

vordenken commented Jul 18, 2026

Copy link
Copy Markdown
Owner

I have never seen this player in my life lol
EDIT: Ok looks like this is the safari "Video-viewer". Do you use this player when switching tabs/windows?

@piekay

piekay commented Jul 18, 2026

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants