Skip to content

feat(web): bidirectional message channel between page and background worker - #708

Draft
ened wants to merge 3 commits into
mainfrom
feat/web-worker-messaging
Draft

feat(web): bidirectional message channel between page and background worker#708
ened wants to merge 3 commits into
mainfrom
feat/web-worker-messaging

Conversation

@ened

@ened ened commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds free-form two-way messaging between the app and the background worker on web, complementing request/response task execution.

  • WorkerProtocol: new message (page -> worker) and workerMessage (worker -> page) wire types
  • WorkmanagerExecution: messageHandler + sendToPage hooks on the Flutter-free dispatcher side
  • WorkmanagerWebWorker runtime: routes messages and wires sendToPage for both the dedicated Web Worker (postMessage) and the Service Worker (clients.postMessage)
  • WorkmanagerWeb: sendMessageToWorker() + workerMessages stream, including the in-page fallback path
  • Example: live worker chat with a simulated price-watch use case; demo UI simplified (tabs, auto-registered task)

No IsolateNameServer equivalent exists on web — this is the postMessage/IndexedDB communication model.

Verification

  • dart analyze clean (package + example)
  • 19 VM tests + 2 real-Chrome Web Worker round-trip tests pass (incl. new message type)
  • flutter build web builds; web/background.dart.js rebuilt

ened added 3 commits August 2, 2026 23:03
…worker

Adds free-form two-way messaging between the app and the background worker,
complementing request/response task execution:

- WorkerProtocol: new 'message' (page -> worker) and 'workerMessage'
  (worker -> page) wire types
- WorkmanagerExecution: messageHandler + sendToPage hooks on the Flutter-free
  dispatcher side
- WorkmanagerWebWorker runtime: routes messages and wires sendToPage for both
  the dedicated Web Worker (postMessage) and the Service Worker
  (clients.postMessage)
- WorkmanagerWeb: sendMessageToWorker() + workerMessages stream, including the
  in-page fallback path

The web example demonstrates the channel with a live worker chat and a
simulated price-watch use case (watch/stop/check messages, live ticks, and
background task checks). Rebuilt web/background.dart.js.
… fewer buttons

The web demo had five action buttons plus four chips stacked with the chat
and the event log. Rework it around two tabs:

- Worker chat: conversation + message input + three action chips
- Task log: single 'Run check now' action + event list

The periodic price-check task is now registered automatically on startup so
the demo works with zero setup; cancel moved to the app bar menu. Status is
a single line instead of a paragraph.
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