Skip to content

Implement user scripts, script messages and URL schemes - #21

Merged
colemancda merged 3 commits into
masterfrom
feature/web-scripts-and-schemes
Nov 23, 2026
Merged

colemancda merged 3 commits into
masterfrom
feature/web-scripts-and-schemes

Conversation

@colemancda

@colemancda colemancda commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Implements user scripts, script messages and URL schemes for web views, from PureSwift/AppRuntime#37, over PureSwift/WebKit's WPEWebContent.

Builds on PureSwift/AppRuntime#37, now merged into AppRuntime's master, which this builds against.

LinuxWebContent

  • features() says userScripts, scriptMessages, messageReplies and urlSchemes when WPE WebKit is installed, and nothing when it isn't. It doesn't claim any browser features.
  • make(_:dataStore:options:schemes:) makes the page and registers each scheme with WPEWebContent.registerURLScheme. A scheme WebKit loads itself, such as https, is left to it, and a warning is logged.
  • User scripts and message handlers go straight to the engine's page.
  • Replies and scheme requests are numbered for the guest, counting up from 1 per page.
    • An answer to a number that's already answered, or never given, does nothing.
    • Headers are passed as names and values in turn.
    • A request's method and body reach the guest.
    • A failed request fails the page's load with the guest's error code.
  • Releasing the page rejects the replies it owes and fails its requests, both with "the page went away".
  • No stopURLSchemeTask on Linux: WPE doesn't say when a page stops wanting a request. The plan's §8 says so.

Testing

On aarch64 Debian 13, Swift 6.4.2, WPE 2.48.3 (the development image), with APPRUNTIME_PATH pointing at AppRuntime#37's branch, as merged:

  • Three new WebContentTests:
    • saysWhatItDoes: the four feature bits.
    • runsUserScriptsAndPassesOnMessages: a document-start script's message arrives before the page's own scripts run, and replies resolve and reject ({"echo":5} | rejected no zeros). Answering twice, or answering an unknown number, is ignored, and once the handler and scripts are removed the next load has neither.
    • servesAPageFromAnAppScheme: a page loads from test-linux-app:/index.html, then its fetch POSTs to the app's scheme and gets back the status, an exposed header and the body (201 yes stored). A failed request fails the load with notPermitted.
  • All 12 WebContentTests and the render-node test passed three runs in a row, and every test target passes.
  • Not tested: x86_64.

@colemancda
colemancda merged commit 44013e1 into master Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant