feat(plugin-bridge): add RPC bridge #164
Open
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.
Description
The RPC bridge allows both sides to expose methods and call remote methods using a single shared channel. It uses JSON-RPC 2.0 protocol and ES6 Proxy to provide natural method calling syntax like await devTools.refresh(). Errors are automatically serialized and propagated. The implementation is opt-in, allowing coexistence with existing event-based communication patterns.
Related Issue
None
Context
Previously, communication between apps and DevTools used an event-based messaging pattern where each side sent messages and listened for responses. While this was type-safe, it required manual promise management, call ID tracking, and custom request-response handling for each interaction. The RPC bridge provides a method-calling abstraction that automatically handles request-response pairing, promise management, and error propagation. This reduces boilerplate code and provides a more natural API for bidirectional method calls while maintaining backward compatibility with existing event-based communication.
Testing
Unit tests using Vitest cover remote method calls, incoming request handling, error propagation in both directions, and opt-in compatibility with non-RPC messages. Tests use a mock transport layer to verify the full request and response cycle, including error serialization and promise management.