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 Roundups: iOS 14, iPadOS 14
Related Forum: iOS 14

Top Stories

xbox series x controller microsoft

How to Pair a PS5 DualSense and Xbox Series X Controller With iPhone, iPad, and Apple TV

Monday May 10, 2021 1:07 pm PDT by
With the release of iOS 14.5 and tvOS 14.5, Apple users can now connect their PS5 DualSense and Xbox Series X controllers to an iPhone, iPad, and Apple TV. Keep reading to learn how it works. Since iOS 13 and tvOS 13, users have been able to connect popular console controllers to an iPhone or Apple TV to play Apple Arcade games and other iOS games, instead of having to spend extra money on...
how to take burst photos iphone 11

How to Delete Redundant Burst Mode Photos on iPhone and iPad

Thursday April 8, 2021 4:37 pm PDT by
Burst Mode refers to when the camera on your iOS device captures a series of photos in rapid succession, at a rate of ten frames per second. It's a great way to shoot an action scene or an unexpected event, since you're always more likely to end up with the picture you were aiming for. Whenever you take a series of burst photos, they automatically appear in the Photo app under the Album name ...
mozilla firefox banner

How to Clear Cookies in Firefox on Mac and iOS

Monday April 19, 2021 11:24 am PDT by
Whenever you browse the web in Firefox, the browser stores website data including cookies so that it doesn't have to do so again each time you revisit a site. In theory this should speed up your browsing experience, but there are some scenarios where you might want to clear the cache and start anew. Keep reading to learn how it's done on Mac, iPhone, and iPad. There are a couple of...
Apple Podcasts iOS 14 5

iOS 14.5: How to Automatically Download New Podcast Episodes and Follow Shows

Tuesday April 27, 2021 5:21 pm PDT by
In iOS 14.5, Apple has made some notable changes to its native Podcasts app. Some of these changes reflect the fact that Apple announced an optional paid podcast subscription service (beginning May 2021), while others are interface improvements to make it easier to find, follow, and listen to new episodes. One example of these changes is the new Smart play button, which is designed to help...
apple card 1

How to Share Your Apple Card With Family

Tuesday May 25, 2021 4:48 pm PDT by
‌Apple Card‌ Family allows families and friends to share a single ‌Apple Card‌ with users above 13 years old, and includes the ability to set a spending limit. The process for sharing an ‌Apple Card‌ with a friend or teenager is enabled on iPhones running iOS 14.6 or later and requires that you are in the same iCloud Family as the person you wish to share the card with. The...
apple card hands

How to Add a Co-Owner to Apple Card

Tuesday May 25, 2021 4:51 pm PDT by
‌Apple Card‌ enables couples to co-own a single ‌Apple Card‌, allowing them to build their credit score together. The process is similar to sharing an ‌Apple Card‌ with your teenager or friend but requires that you share your spouse's annual income. As co-owners, remember that the both of you share responsibility for all account activity, including the payment of balances. The process for ...
photos icon

How to Back Up Your iPhone Photos

Wednesday May 12, 2021 9:26 am PDT by
Backing up the photos you take on your iPhone might not sound like a thrilling prospect, but it's far from a thankless task. On the contrary, it's a crucial step in ensuring that your most precious pictures are never lost. Plus, once you have a system for backing up your photos in place, you can get on with enjoying taking pictures with your smartphone in the confidence that they're safe. You...
m1 mac family

How to Record Your Mac's Screen

Tuesday May 18, 2021 3:41 pm PDT by
If you've ever wanted to record a video of your Mac's screen but don't know quite how to do so, then you've come to the right place. Keep reading to learn how you can record any Mac desktop activity in just a few simple steps. Recording the activity on your Mac's screen can be useful for a number of reasons. For example, if you want to teach someone how to perform a particular function on...
safari macos icon banner

How to Clear Safari's Cache

Tuesday March 23, 2021 5:32 pm PDT by
Whenever you browse the web in Safari, the browser stores website data so that it doesn't have to download it again each time you revisit a site. In theory this should speed up your browsing experience, but there are some scenarios where you might want to clear the cache and start anew. Keep reading to learn how it's done on Mac, iPhone, and iPad. There are a couple of situations where you...
safari macos icon banner

How to Check iCloud Keychain Password Security

Tuesday May 11, 2021 5:29 pm PDT by
Using iCloud Keychain, Apple's Safari browser stores and syncs all the passwords you use for different websites and apps through iCloud. And in iOS 14 and later, Apple provides security recommendations that warn you if a password you're using is putting your accounts at risk. Safari securely monitors your saved passwords using strong cryptographic techniques, and regularly checks derivations ...