Please Help: WKwebview not allowing background audio playback

I’ve been working on a personal iOS project for fun — essentially a YouTube music player, learning how background media playback works in native iOS apps.

After seeing that Musi (a famous music streaming app) can play YouTube audio in the background with the screen off — I got really curious. I’ve been trying to replicate that basic background audio functionality for YouTube embeds using WKWebView. I've spent a crazy amount of time (probably 20 hours) trying to figure this out but have achieved no success.

Here’s what I’ve tried so far:

-Embedding a YouTube video in a WKWebView

-Activating AVAudioSession with .playback and setting .setActive(true)

-Adding the UIBackgroundModes key with audio in Info.plist

-Adding the NSAppTransportSecurity key to allow arbitrary loads

--Testing on a real device (iPhone 14, iOS 18.1 target)--

What happens:

Audio plays fine in the foreground.

If I exit the app and go to the lock screen quickly enough (less than 3 seconds) after pressing play, I can resume playback briefly from the lock screen — but it doesn’t automatically continue like in Musi and other apps like it.

Most of the time, the audio stops when the app is backgrounded.

I get this error consistently in the logs:

Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 "(originator doesn't have entitlement com.apple.runningboard.assertions.webkit AND originator doesn't have entitlement com.apple.multitasking.systemappassertions)"

It seems like the app lacks some specific entitlements related to WebKit media playback. I don’t have AppDelegate/SceneDelegate (using SwiftUI), but can add if needed.

I’m super curious how music streaming apps using youtube as a source get around this — are they doing something different under the hood? A custom player? A SafariViewController trick? Is there a specific way to configure WKWebView to keep playing in the background, or is this a known limitation?

Would really appreciate any insight from folks who’ve explored this before or know how apps like Musi pulled it off.

Thanks in advance!

Please Help: WKwebview not allowing background audio playback
 
 
Q