Menu

1 / 2

Safari's native messaging can't stream, so I long-poll the on-device model

DEV Community: ios·Alex Panchenko·8 days ago
#NIpfip0G
#devtoios#devto#dev#model#swift
Long article (1314 words) — no AI summary yet.
Reading 0:00
15s threshold

TL;DR. sendNativeMessage in Safari returns exactly one reply. To stream a model's output through it,

the background script asks "anything after character N?" in a loop, and the Swift side holds each

request for up to a second until the text grows. Every reply carries the whole text so far, counted in

UTF-16. Then keep the background script alive yourself, and don't write to storage.session per poll.

I'm working on Epitome, a Safari extension for Mac, iPhone and iPad. It summarizes the current page with

the model Apple ships on the device (the Foundation Models framework).

On my MacBook Pro with an M5 Pro the first words come back after about two seconds, and a summary of a

long article takes 8 to 15. These are my numbers, not a benchmark: on other Macs and on iPhones they'll

be different.

When I tried showing nothing for 15 seconds and then the whole text at once, it felt like the extension

had hung.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.