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

Apple Silicon AI Optimized Feature Siri

Apple Releases Open Source AI Models That Run On-Device

Wednesday April 24, 2024 3:39 pm PDT by
Apple today released several open source large language models (LLMs) that are designed to run on-device rather than through cloud servers. Called OpenELM (Open-source Efficient Language Models), the LLMs are available on the Hugging Face Hub, a community for sharing AI code. As outlined in a white paper [PDF], there are eight total OpenELM models, four of which were pre-trained using the...
iOS 18 Siri Integrated Feature

iOS 18 Rumored to Add These 10 New Features to Your iPhone

Wednesday April 24, 2024 2:05 pm PDT by
Apple is set to unveil iOS 18 during its WWDC keynote on June 10, so the software update is a little over six weeks away from being announced. Below, we recap rumored features and changes planned for the iPhone with iOS 18. iOS 18 will reportedly be the "biggest" update in the iPhone's history, with new ChatGPT-inspired generative AI features, a more customizable Home Screen, and much more....
maxresdefault

Apple Announces 'Let Loose' Event on May 7 Amid Rumors of New iPads

Tuesday April 23, 2024 7:11 am PDT by
Apple has announced it will be holding a special event on Tuesday, May 7 at 7 a.m. Pacific Time (10 a.m. Eastern Time), with a live stream to be available on Apple.com and on YouTube as usual. The event invitation has a tagline of "Let Loose" and shows an artistic render of an Apple Pencil, suggesting that iPads will be a focus of the event. Subscribe to the MacRumors YouTube channel for more ...
Apple Vision Pro Dual Loop Band Orange Feature 2

Apple Cuts Vision Pro Shipments as Demand Falls 'Sharply Beyond Expectations'

Tuesday April 23, 2024 9:44 am PDT by
Apple has dropped the number of Vision Pro units that it plans to ship in 2024, going from an expected 700 to 800k units to just 400k to 450k units, according to Apple analyst Ming-Chi Kuo. Orders have been scaled back before the Vision Pro has launched in markets outside of the United States, which Kuo says is a sign that demand in the U.S. has "fallen sharply beyond expectations." As a...
iPad And Calculator App Feature 1

Apple Finally Plans to Release a Calculator App for iPad Later This Year

Tuesday April 23, 2024 9:08 am PDT by
Apple is finally planning a Calculator app for the iPad, over 14 years after launching the device, according to a source familiar with the matter. iPadOS 18 will include a built-in Calculator app for all iPad models that are compatible with the software update, which is expected to be unveiled during the opening keynote of Apple's annual developers conference WWDC on June 10. AppleInsider...
macbook pro purple february

Best Buy Introduces Record Low Prices on Apple's M3 MacBook Pro for Members

Thursday April 25, 2024 7:41 am PDT by
Best Buy is discounting a collection of M3 MacBook Pro computers today, this time focusing on the 14-inch version of the laptop. Every deal in this sale requires you to have a My Best Buy Plus or Total membership, although non-members can still get solid second-best prices on these MacBook Pro models. Note: MacRumors is an affiliate partner with Best Buy. When you click a link and make a...