Skip to content

Add WebView on iOS support with a note specifying the limitations - #30146

Open
Bashamega wants to merge 1 commit into
mdn:mainfrom
Bashamega:main
Open

Bashamega wants to merge 1 commit into
mdn:mainfrom
Bashamega:main

Conversation

@Bashamega

Copy link
Copy Markdown
Contributor

Summary

This PR adds webview on iOS support with a not specifying the limitations

Test results and supporting details

stackoverflow.com/a/64155509/3255152

webkit.org/blog/10882/app-bound-domains

Related issues

fixes #27470

@github-actions github-actions Bot added data:api Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API size:xs [PR only] 0-6 LoC changed labels Jul 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Tip: Review these changes grouped by change (recommended for most PRs), or grouped by feature (for large PRs).

Comment thread api/ServiceWorker.json
"version_added": false
"version_added": "14",
"partial_implementation": true,
"notes": "Works only with App Bound Domains (up to 10 domains) and for apps with the Web Browser entitlement."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This note needs to explain what "works" means. I'd expect to see something like…

The ServiceWorker API is not exposed unless the webview is configured for app bound domains…

Or depending on the particulars, this data might somewhere else, e.g.,:

The navigator.serviceWorker.register() method throws unless the webview is configured for app bound domains…

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I don't know the particulars for it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NiklasMerz Do you know anything about this? Something worth recording in BCD?

If not, we'll close this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't used ServiceWorkers in WKWebView myself but this limitation seems to be correct. I found multiple sources and this WebKit bug: https://bugs.webkit.org/show_bug.cgi?id=206741. That also states it's supported only for HTTP and HTTPs whereas some WebView developers (including Cordova, Capacitor) use custom schemes.

Supporting ServiceWorker only with AppBound domains and HTTP(S) is a serious limitation worth recording in BCD I think.

@ddbeck ddbeck Aug 5, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @NiklasMerz! One follow up: do you have any idea how the limitation manifests? The linked bug doesn't explain what lack of support means exactly (e.g., does "serviceWorker" in navigator return false? Is ServiceWorker exposed regardless? Or is there some kind of exception on registration?).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, where do I set the domains for "App-Bound Domains"?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to set the domains in Info.plist (there is an UI for that not sure what it's called from memory) and then webViewConfiguration.limitsNavigationsToAppBoundDomains = YES;

https://webkit.org/blog/10882/app-bound-domains/

(I tried AppBoundDomains many years ago but it didn't work for my use case so I'm not sure how it works today).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got Florians PR to work and the next version of CanIWebView 1.1.0 will have collector.openwebdocs.org as an AppBoundDomain. You can enable limitsNavigationsToAppBoundDomains on the config tab.

The update is in review for the App Store so keep an eye out for Apple to approve and publish it.

In my local build the BCD collector tests somehow get stuck at "Running tests for Service Worker" when I enable that setting. Looks like they still don't work and I get this in the logs:

[Log] Running tests for Service Worker... (harness.js, line 59)
[Error] Unhandled Promise Rejection: TypeError: Job rejected for non app-bound domain
[Error] WebSocket connection to 'wss://echo.websocket.org/' failed: Ungültige Antwort vom Server. (x5)

The Service Worker test might need to be adjusted.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, at least I can see an exposure change when running the collector in the app. Without AppBoundDomain https://collector.openwebdocs.org/tests/api/ServiceWorker?exposure=Window tests are false, and they are true when AppBoundDomain is enabled.

So, that I think answers Daniel's questions above.

Not sure what is going on when running the full collector tests. Is there a way to get to the error console myself in the app?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK you can only really go into the console and debugger if you build and run the app yourself. Production builds from the App Store are not debuggable.

If you have a mac you can clone the repo, open it in Xcode and you should be able to build and run the app using the free developer account. (I can invite you to a paid account as well if needed). Apple signing stuff is always a bit finicky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data:api Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API size:xs [PR only] 0-6 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

api.ServiceWorker - WebView on iOS does have support via App Bound Domains

4 participants