In iOS 14, Apple added a Picture in Picture mode on iPhone that lets you watch a video in a small screen on your device while you continue to do other things on the phone.

YouTube Picture in Picture
Picture in Picture mode doesn't work in the YouTube app, although it was possible to watch videos in Picture in Picture on YouTube's mobile website through Safari until YouTube intentionally nixed the workaround last week, presumably to push people to buy a Premium subscription. For a short while, you could still get Picture in Picture to work on YouTube.com in Safari if you request the desktop site, but YouTube has since blocked that as well.

But thanks to CodeEverywhere, there's now another neat workaround that uses a snippet of JavaScript and no external plugins to suppress the Picture in Picture block that YouTube has added to its mobile site.

As noted by CodeEverywhere, the same code can also be used in an iOS Shortcut that can then be selected from Safari's Activity view (formerly called the Share Sheet) whenever you want to watch a YouTube-hosted video in Picture in Picture.

Using CodeEverywhere's script, software engineer Jonas Reitmann has since created a Shortcut and made it available for download (Note: people are having trouble with the direct download shortcut working. Follow the directions below), but if you are uncomfortable downloading a shortcut blindly, you can recreate it with the steps below.

How to Create a Shortcut for YouTube Picture in Picture

  1. Launch the Shortcuts app on your ‌iPhone‌ and click the plus (+) icon in the top-right corner of the screen to create a new shortcut.
    shortcuts

  2. Tap Add Action.
    shortcuts

  3. Select Web.
    shortcuts

  4. Under "Safari," select Run JavaScript on Web Page.
    shortcuts

  5. Where it says "Run JavaScript on" tap the blue words Web Page, then select Shortcut Input in the pop-up menu.
    shortcuts

  6. Remove the existing JavaScript code in the shortcut window and paste in the following code:
    let v = document.querySelector('video');

    v.addEventListener('webkitpresentationmodechanged', (e)=>e.stopPropagation(), true);

    setTimeout(()=>v.webkitSetPresentationMode('picture-in-picture'), 3000);

    completion()
    shortcuts

  7. Tap the three dots icon in the top-right corner of the screen.
    shortcuts

  8. Give your shortcut a name, e.g. "YouTube PiP," then toggle the switch next to Show in Share Sheet to the green ON position.
    shortcuts

  9. Tap Share Sheet Types, then select Deselect All and tap Safari web pages.
    shortcuts

  10. Return to the Details screen, then tap Done.
    shortcuts

  11. Tap Done to finish.
    shortcuts

With that done, simply select the Shortcut in Safari via the Action icon whenever you want to use Picture in Picture on YouTube's mobile website, no premium subscription required.

safari

Related Forum: iOS 14

Popular Stories

iOS 18 CarPlay Feature

iOS 18 Adds These 5 New Features to CarPlay

Thursday June 13, 2024 7:44 am PDT by
Apple did not mention CarPlay during its WWDC keynote this week, but iOS 18 includes a handful of new features for the in-car software. Overall, there is not a whole lot new for CarPlay on iOS 18, with changes seemingly limited to the Messages and Settings apps so far. Below, we recap everything new for CarPlay on iOS 18. New for CarPlay on iOS 18 1. Contact Photos in Messages App...
ios 18 button bulge

iOS 18 Adds Pop-Out Bezel Animation When Pressing iPhone Buttons

Tuesday June 11, 2024 10:40 am PDT by
iOS 18 includes a small but interesting change for the buttons on the iPhone, adding more of a visual element when changing volume, activating the Action button, or locking the screen. When you press an iPhone button in iOS 18, the display bezel bulges outward slightly. This feature is available for the volume buttons, Action button and the power button, and it will also likely be used for...
maxresdefault

First Look at Messages via Satellite in iOS 18

Thursday June 13, 2024 11:29 am PDT by
Apple has been gradually expanding its suite of satellite connectivity features for iPhone, and iOS 18 brings a significant new one in the form of Messages via satellite. The feature allows users to send and receive iMessages and SMS texts, including emoji and Tapbacks, while out of range of cellular and Wi-Fi networks. CNET met up with Apple's senior director of platform product marketing,...
iOS 18 Wallet Feature

Here's What's New in Apple Wallet on iOS 18 for Event Tickets and More

Friday June 14, 2024 7:32 am PDT by
iOS 18 includes a handful of enhancements to the Wallet app on the iPhone, with new features for Apple Pay, Apple Cash, event tickets, and more. Below, we outline everything new for the Wallet app on iOS 18, based on information from Apple's press release and a WWDC 2024 coding session. Redesigned Event Tickets Event tickets have an all-new design in the Wallet app on iOS 18, complete...