Skip to content

Webview with Custom User Agent #4

@jwcounts

Description

@jwcounts

Is it possible to use this package with a custom user agent? I'm trying to migrate a prototype app I created into SKIP, and I was previously able to do it like this:

import WebKit

struct WebView: UIViewRepresentable {
	var payload: String
   
	func makeUIView(context: Context) -> WKWebView {
		let webview: WKWebView = {
			let configuration = WKWebViewConfiguration()
			configuration.mediaTypesRequiringUserActionForPlayback = []
			configuration.allowsInlineMediaPlayback = true
			configuration.allowsPictureInPictureMediaPlayback = true
			return WKWebView(frame: .zero, configuration: configuration)
		}()
		webview.isInspectable = true
		webview.customUserAgent = "Custom User Agent Here"
		return webview
	}

	func updateUIView(_ uiView: WKWebView, context: Context) {
		var request = URLRequest(url: URL(string: payload)!)
		request.setValue("encrypted-media=*;geolocation=*;fullscreen=*;picture-in-picture=*", forHTTPHeaderField: "Permissions-Policy")
		uiView.load(request)
	}
}

For context: I am loading a page with a video player that is playing a DRM-encrypted stream. Using WKWebView, the player would only load properly on a device and if I set a custom user agent (long story, can explain further if needed).

Using SkipWeb, I can get the page to load on both iOS and Android, but neither will play the video.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions