Feat: window.infiniframe in the JS window, proper InteropEnvelope messaging, and InfiniFrame.Js optimizations#214
Merged
AnnaSasDev merged 30 commits intocorefrom Apr 12, 2026
Conversation
…alidation and structured communication - Added `InteropEnvelopeProtocol` and `InteropEnvelopeParseResult` for defining, creating, and parsing JSON-based messages. - Updated TypeScript and JavaScript implementations to support the JSON envelope format. - Replaced legacy `messageId;payload` format with versioned JSON envelopes in host-frontend communication. - Refactored message handling workflows in both C# and JavaScript to adapt to the new protocol. - Updated tests to validate envelope creation, parsing, and error scenarios. - Modified migration guide to include details on transitioning to the new JSON message format.
- Deleted all TypeScript source files in the `InfiniFrame.Js/TsSource` directory. - Removed `package.json`, `package-lock.json`, and associated npm scripts. - Uninstalled TypeScript, webpack, and other related development dependencies. - Eliminated all references to InfiniFrame JavaScript from the project.
Add a new Contracts/IInteropEnvelope.ts file containing InteropEnvelopeV1, ParsedInteropMessage, and ParseError interfaces, and update Interop/InteropEnvelopeProtocol.ts to import these types instead of declaring them inline. Consolidates type definitions to a single contract file to reduce duplication and improve reuse; no functional changes to protocol logic.
5 tasks
…ove interop flow: - Removed `isBlazorMessage` and `handleWebMessage` methods. - Introduced `handleInteropMessage` for unified message processing. - Updated WebView2 and external message receivers to use the new method for cleaner handling and improved validation.
- Introduced `RegisterWindowCreatedUtilityTests` to cover edge cases and ensure idempotent registration handling. - Added `WindowRegistrationState` and `ReadyRegistrationState` classes to encapsulate state tracking and improve readability. - Refactored `RegisterWindowCreatedUtility` to implement explicit ready handshake monitoring, retry logic, and timeout handling for enhanced reliability. - Improved logging to track handshake timeouts and retry attempts.
- Moved `InteropEnvelopeProtocol` to the `InfiniFrame.Js.Interop` namespace and refactored implementation for optimized serialization and cleaner message parsing. - Reorganized `Utilities` into `MessageHandlers` for improved structure and responsibility segregation. - Renamed `ReadyRegistrationState` to `WindowReadyRegistrationState` and updated associated logic for clarity and AOT compatibility. - Updated `InfiniFrame.Js.csproj` to include `InternalsVisibleTo` for `InfiniFrameTests`.
…p` for improved organization
…d initialization logic adjustments
… item updates for improved visibility and output management. Add fallback logic for resolving native artifacts in `PublishService`.
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
window.infiniframe in the JS window, proper InteropEnvelope messaging, and InfiniFrame.Js optimizations
- Introduced `HostBridge` to encapsulate message dispatch logic and simplify integration with platform transports. - Added fallback to legacy `window.external.sendMessage` for backwards compatibility. - Updated protocol definitions to include support for channels and refined JSON envelope processing. - Migrated existing references to use `window.infiniframe.host.postMessage`. - Enhanced protocol handling in C#, JavaScript, and documentation to support structured envelopes alongside legacy formats.
…iframe.host` for message handling: - Removed legacy `window.external.sendMessage` and `window.external.receiveMessage` support across all platforms. - Updated JavaScript interop examples and documentation to reflect the new API. - Revised TypeScript definitions and C# integration points to enforce `window.infiniframe.host` usage. - Simplified HostBridge implementation by removing legacy transport fallbacks and warning logic.
- Introduced `host.receiveMessage` to handle incoming messages from the host. - Updated `HostBridge` to register a web message receiver with platform-specific fallbacks. - Expanded HostBridge logic to support and validate receive message transport options. - Minor adjustments to ensure seamless integration with existing host message orchestration.
…h resolution: - Added fallback logic for `SolutionDir` using `RepoRootDir` in `Directory.Build.props`. - Updated Playwright build step to pass `SolutionDir` explicitly in the GitHub Actions workflow.
…igration: - Updated JavaScript evaluations to align with `window.infiniframe.host` API. - Adjusted server test utility initialization to improve resource handling and readability.
…e output management - Introduced distinct `BuildFrontendCrossTargeting` and `BuildFrontendSingleTarget` targets for conditional frontend build handling. - Added `CopyFrontendToOutput` target to streamline copying frontend assets to the output directory post-build. - Removed redundant `Content` item group for `wwwroot`.
…efine steps for each framework version (net8.0, net9.0, net10.0).
Update CI workflow (.github/workflows/ci-testing.yml) to set the run_windows_playwright input default to true. This makes Windows Playwright tests run by default while preserving the input so it can still be overridden when needed.
…etup path - Added a step to prepare the WebView2 cache directory for better path consistency. - Updated caching and installation logic to use the new `.cache\webview2` directory.
…prove HostBridge envelope handling: - Updated `RegisterWindowCreatedUtility` to lock using `registrationState.Lock`. - Removed unused `LegacyProtocolWarningByMessageId` and related warning logic. - Enhanced `HostBridge` to prefer string envelope serialization with backward compatibility for legacy adapters.
- Added `RegistrationSendInProgress` property to track ongoing registration attempts. - Updated `RegisterWindowCreatedUtility` to prevent duplicate registration attempts by checking this new property. - Refactored `SendRegistrationsWithRetryAsync` to handle state updates and track registration progress more effectively.
- Introduced `--native-artifacts-fallback` and `--allow-stale-native-fallback` options for better control over fallback artifact usage. - Added support for `INFINIFRAME_PACK_NATIVE_ARTIFACTS_FALLBACK` and `INFINIFRAME_PACK_ALLOW_STALE_NATIVE_FALLBACK` environment variables. - Refactored fallback resolution logic to improve clarity and error handling.
…avaScript interop validation, and fix frontend build target condition: - Replaced `CapturingLogger` with `RecordingInfiniFrameWindowSubstitute` in tests for cleaner and more maintainable web message tracking. - Enhanced JavaScript interop validation to cover additional `infiniframe.host` API properties. - Fixed an issue with the `BuildFrontendSingleTarget` condition in Playwright test project to correctly target frameworks.
…payload` messaging protocol: - Expanded guides and migration docs to explain `--native-artifacts-fallback` and stale fallback policy requirements. - Emphasized support for JSON envelope protocol in JavaScript messaging and clarified removal of legacy format.
…eMachine`: - Replaced individual state properties with `WindowRegistrationStateMachine` for cleaner state tracking. - Updated `RegisterWindowCreatedUtility` to leverage new state machine logic, improving registration flow and timeout handling. - Added `WindowRegistrationHandshakeState` enum to simplify handshake state representation.
…erop validation: - Introduced `InteropEnvelopeProtocol.test.ts` and `HostBridge.test.ts` for protocol and host bridge validation. - Added `vitest.config.ts` to configure testing environment and enable coverage reports. - Updated `package.json` scripts to support test execution, coverage reporting, and watch mode. - Enhanced `.csproj` configuration to include test content visibility in the project.
…rame.Js`: - Created `InfiniFrameTests.Js` project with supporting `.csproj` and solution updates. - Migrated tests to `InfiniFrameTests.Js` namespace for consistency. - Added new unit tests including `MessageHandlersTests`, `ServiceCollectionExtensionsTests`, and `WindowRegistrationStateMachineTests`. - Enhanced `InfiniFrameJs` coverage with tests for `SetPointerCaptureAsync` and `ReleasePointerCaptureAsync`.
… IDisposable' Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
…ne' may silently drop its earlier arguments' Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
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.
Summary
This PR migrates InfiniFrame host messaging to a structured JSON envelope protocol and standardized
window.infiniframe.hostbridge, with coordinated updates across core/native/JS layers, docs, tests, and CI.Type of Change
Changes Introduced
messageId;payloadto versioned JSON envelopes ({ id, data, version, channel? }) with unified parsing/validation in C# and TypeScript.window.infiniframe.host.postMessage(...)andwindow.infiniframe.host.receiveMessage(...)across Windows/macOS/Linux native injectors, JS runtime, examples, docs, and tests.__infiniframe:ready) with deferred registration messaging, timeout monitoring, idempotency, and retry logic.InfiniFrame.Jssource/build layout (TsSource→TypeScript, npm config moved undersrc/InfiniFrame.Js, csproj/npm targets updated).InfiniFrame.Tools.Pack.net8.0/net9.0/net10.0, improved artifact upload and WebView2 cache handling.Related Issues
Closes #215
Closes #195
Closes #190
Closes #186
Closes #175
Closes #174
Closes #92
Closes #87
Checklist
📖 Additional Context
window.external.*towindow.infiniframe.host.*.version: 1; protocol parsing includes compatibility safeguards and explicit rejection paths.