Skip to content

Feat: window.infiniframe in the JS window, proper InteropEnvelope messaging, and InfiniFrame.Js optimizations#214

Merged
AnnaSasDev merged 30 commits intocorefrom
195-feature-migrate-host-messaging-protocol-to-structured-json-envelope
Apr 12, 2026
Merged

Feat: window.infiniframe in the JS window, proper InteropEnvelope messaging, and InfiniFrame.Js optimizations#214
AnnaSasDev merged 30 commits intocorefrom
195-feature-migrate-host-messaging-protocol-to-structured-json-envelope

Conversation

@AnnaSasDev
Copy link
Copy Markdown
Member

@AnnaSasDev AnnaSasDev commented Apr 11, 2026

Summary

This PR migrates InfiniFrame host messaging to a structured JSON envelope protocol and standardized window.infiniframe.host bridge, with coordinated updates across core/native/JS layers, docs, tests, and CI.

Type of Change

  • Bug fix (non-breaking change fixing an issue)
  • New feature (non-breaking change adding functionality)
  • Breaking change (fix or feature impacting existing APIs)
  • Refactor / Code cleanup (no functional change)
  • Documentation update
  • Test addition or update
  • Other (please describe): CI/workflow and build pipeline updates

Changes Introduced

  • Migrated JS↔host messaging from legacy messageId;payload to versioned JSON envelopes ({ id, data, version, channel? }) with unified parsing/validation in C# and TypeScript.
  • Replaced/standardized runtime bridge usage to window.infiniframe.host.postMessage(...) and window.infiniframe.host.receiveMessage(...) across Windows/macOS/Linux native injectors, JS runtime, examples, docs, and tests.
  • Added interop protocol safety features: payload size cap, strict version checks, malformed envelope rejection, and legacy-format migration warnings.
  • Introduced window-ready handshake orchestration (__infiniframe:ready) with deferred registration messaging, timeout monitoring, idempotency, and retry logic.
  • Refactored InfiniFrame.Js source/build layout (TsSourceTypeScript, npm config moved under src/InfiniFrame.Js, csproj/npm targets updated).
  • Improved packaging/build resilience with fallback native artifact resolution in InfiniFrame.Tools.Pack.
  • Updated CI: Windows Playwright enabled by default, framework execution flow revised for net8.0/net9.0/net10.0, improved artifact upload and WebView2 cache handling.
  • Added new tests for interop envelope protocol and window-created registration behavior; updated Playwright JS tests to assert new host bridge API.

Related Issues

Closes #215
Closes #195
Closes #190
Closes #186
Closes #175
Closes #174
Closes #92
Closes #87

Checklist

  • My code follows InfiniFrame's coding conventions
  • I added comments for complex or non-obvious code
  • Documentation updated (if applicable)
  • All tests pass locally
  • Added new tests for any new functionality
  • Existing tests pass
  • No new warnings or errors introduced
  • PR only includes changes relevant to the issue / feature

📖 Additional Context

  • This PR includes an interop API migration: consumers should move from window.external.* to window.infiniframe.host.*.
  • The envelope contract currently uses version: 1; protocol parsing includes compatibility safeguards and explicit rejection paths.
  • CI and JS build path changes were required to support the new repo layout and stabilize Playwright execution across frameworks.

…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.
@AnnaSasDev AnnaSasDev linked an issue Apr 11, 2026 that may be closed by this pull request
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`.
… item updates for improved visibility and output management. Add fallback logic for resolving native artifacts in `PublishService`.
Comment thread src/InfiniFrame.Js/Interop/RegisterWindowCreatedUtility.cs Fixed
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@AnnaSasDev AnnaSasDev changed the title Feat: proper InteropEnvelope messaging and InfiniFrame.Js optimizations Feat: window.infiniframe in the JS window, proper InteropEnvelope messaging, and InfiniFrame.Js optimizations Apr 11, 2026
- 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.
@AnnaSasDev AnnaSasDev self-assigned this Apr 12, 2026
…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.
Comment thread tests/InfiniFrameTests.Js/InteropEnvelopeProtocolTests.cs Fixed
…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`.
Comment thread tests/InfiniFrameTests.Js/InfiniFrameJsTests.cs Fixed
Comment thread tests/InfiniFrameTests.Js/InteropEnvelopeProtocolTests.cs Fixed
AnnaSasDev and others added 2 commits April 12, 2026 16:22
… 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>
@AnnaSasDev AnnaSasDev merged commit f4b38a5 into core Apr 12, 2026
57 checks passed
@AnnaSasDev AnnaSasDev deleted the 195-feature-migrate-host-messaging-protocol-to-structured-json-envelope branch April 12, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment