Implement native Android PebbleBridge#300
Draft
caco3 wants to merge 4 commits into
Draft
Conversation
- Add fetch, WebSocket, encrypted storage, and close() bridge APIs - Inject window.pebbleBridge JS shim via WebView addJavascriptInterface - Gate injection behind config_network_bridge app capability - Maintain legacy pebblejs://close URL interception for compatibility - Place bridge code in pebble module androidMain/commonMain source sets
…ine shim - Add .open()/.message()/.error()/.close() event methods native expects - Accept fetch response as either JSON string or already-parsed object
caco3
force-pushed
the
feature/pebble-bridge
branch
2 times, most recently
from
July 18, 2026 14:18
b932207 to
bc22997
Compare
- Move inline JS shim from PebbleBridgeManager to assets/bridge-shim.js - Share a single Ktor/OkHttp HttpClient between BridgeFetch and BridgeWebSocket - Add WebSocket subprotocol support via Sec-WebSocket-Protocol header - Replace org.json.JSONObject.quote and manual escapeJson with kotlinx.serialization - Add dispose() path that tears down without firing onClose - Remove runBlocking(Dispatchers.Main) in Android factory - Restore localStorage after page finishes loading (LoadingState.Finished)
caco3
force-pushed
the
feature/pebble-bridge
branch
from
July 18, 2026 14:40
50dc77c to
2b489e5
Compare
The HttpClient is shared with BridgeFetch and owned by PebbleBridgeManager. Closing it in BridgeWebSocket.dispose would break fetch operations.
This was referenced Jul 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a native Android bridge (
PebbleBridge) that lets watchapp config pages running in the mobile app’s WebView access capabilities that are normally blocked by WebView sandboxing, CORS, mixed-content rules, or JavaScript restrictions. See #301 for details.When a watchapp declares the
config_network_bridgecapability, its config page receives awindow.pebbleBridgeobject that delegates work to the native side. This allows a config page to:window.pebbleBridge.fetch) — including local or self-hosted services that would otherwise be unreachable from a mobile WebView.window.pebbleBridge.WebSocket) — for streaming live data without WebSocket CORS issues.window.pebbleBridge.storage) — using the app’s encrypted storage instead oflocalStorage, which is not shared across sessions or reliable in a WebView.window.pebbleBridge.close) — replacing the legacypebblejs://close#URL scheme.The bridge is opt-in per watchapp and only activates when the app declares the
config_network_bridgecapability, so existing watchapps are unaffected.Example use cases
For easy testing, I created a minimal demo watchapp, see https://github.com/caco3/bridge-demo. It demonstrates internet access through the config page.
Key changes
NetworkBridge(config_network_bridge) capability detection inLockerAppScreenandPebbleRoutes.bridgeEnabledflag toWatchappSettingsRouteand passed it intoWatchappSettingsScreen.PebbleBridgeNativeInterfaceon the WebView and injects a JS shim that createswindow.pebbleBridge.WebSocket(url, protocols)— WebSocket via Ktor with message/close/error forwardingstorage.get/set/remove— AndroidEncryptedSharedPreferencesBridgeConfigParserto read config values from the URL hash fragment.BridgeModels,BridgeFetch,BridgeStorage, and BridgeWebSocket modules.webViewFactorysignature for source compatibility (no iOS implementation yet).Backward compatibility
Apps that do not declare
config_network_bridgesee no change.Documentation
See coredevices/sdk-docs#17
High-level architecture
Notes