Skip to content

Use cross-origin HTML preview renderer#1407

Open
mwtrew wants to merge 31 commits intomainfrom
1264_cross-origin-html-preview
Open

Use cross-origin HTML preview renderer#1407
mwtrew wants to merge 31 commits intomainfrom
1264_cross-origin-html-preview

Conversation

@mwtrew
Copy link
Copy Markdown
Contributor

@mwtrew mwtrew commented Mar 27, 2026

This moves preview rendering to an iframe with a document loaded cross-origin as a source. This enforces cross-origin separation and gives the preview window it's own localstorage, isolated from the parent. Content is injected into the doc via postMessage().

Most of the logic in the new HtmlRenderer component (besides message handling) has been moved over from HtmlRunner.

This moves preview rendering to an iframe with a document loaded
cross-origin as a source. This enforces cross-origin separation and
gives the preview window it's own localstorage, isolated from the parent.

Content is injected into the doc via `postMessage`.
@mwtrew mwtrew temporarily deployed to previews/1407/merge March 27, 2026 11:40 — with GitHub Actions Inactive
This prevents the project HTML etc. being sent before the renderer
has initialised, which was resulting in the the message being missed
and the Run button appearing to do nothing when initially clicked.
@mwtrew mwtrew temporarily deployed to previews/1407/merge March 27, 2026 20:15 — with GitHub Actions Inactive
mwtrew added 4 commits March 30, 2026 09:39
These tests no longer work, and I'm not sure whether it's possible
to use RTL to read the contents of the new inner iframe. There are
duplicate Cypress tests for many of these, and Cypress is a lot easier
to work with in this case so I will make the changes there.
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 2, 2026 10:16 — with GitHub Actions Inactive
The docs reccommend against this, because it makes utils less flexible.

I'm also trying to deal with some flakiness here, so we'll see if this
helps.
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 6, 2026 10:01 — with GitHub Actions Inactive
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 6, 2026 10:04 — with GitHub Actions Inactive
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 6, 2026 10:51 — with GitHub Actions Inactive
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 6, 2026 11:56 — with GitHub Actions Inactive
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 6, 2026 12:38 — with GitHub Actions Inactive
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 6, 2026 14:31 — with GitHub Actions Inactive
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 6, 2026 15:04 — with GitHub Actions Inactive
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 6, 2026 15:32 — with GitHub Actions Inactive
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 7, 2026 09:29 — with GitHub Actions Inactive
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 7, 2026 09:42 — with GitHub Actions Inactive
@mwtrew mwtrew force-pushed the 1264_cross-origin-html-preview branch from 4c756ab to 8ccd3e6 Compare April 7, 2026 09:51
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 7, 2026 09:51 — with GitHub Actions Inactive
These are not currently working on CI. We may move these to the E2E test
repo.
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 7, 2026 10:01 — with GitHub Actions Inactive
mwtrew added 2 commits April 9, 2026 16:29
This means the embedded mode preview has the full height of the content
as before.
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 9, 2026 15:30 — with GitHub Actions Inactive
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 9, 2026 16:12 — with GitHub Actions Inactive
@mwtrew mwtrew marked this pull request as ready for review April 9, 2026 16:14
Copilot AI review requested due to automatic review settings April 9, 2026 16:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request restructures the HTML preview rendering to use a cross-origin iframe approach instead of the previous blob URL method. The renderer is moved to a separate application that loads at HTML_RENDERER_URL, and content is communicated via postMessage. This enforces security isolation and gives the preview window its own isolated localStorage.

Changes:

  • Create a new webpack configuration and entry point for the HTML renderer as a separate application
  • Refactor HtmlRunner to use postMessage instead of directly manipulating blob URLs in the iframe
  • Create new HtmlRenderer component to handle HTML rendering and message passing
  • Move iframe origin validation logic to a shared utility module
  • Remove legacy test cases that were specific to the old blob URL approach

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
webpack.html-renderer.config.js New webpack configuration for building the HTML renderer as a separate bundle
src/html-renderer.jsx New entry point for the HTML renderer application
src/utils/iframeUtils.js New utility module for iframe security validation and message constants
src/components/Editor/Runners/HtmlRunner/HtmlRenderer.jsx New component that handles HTML rendering and cross-origin communication
src/components/Editor/Runners/HtmlRunner/HtmlRunner.jsx Refactored to use postMessage instead of blob URLs
src/components/ScratchEditor/ScratchIntegrationHOC.jsx Updated to use shared iframe utility function
src/components/Editor/Runners/HtmlRunner/HtmlRunner.test.js Removed tests specific to old blob URL approach
.github/workflows/deploy.yml Updated deployment pipeline to build and deploy HTML renderer separately
package.json Added build and start scripts for HTML renderer
Other supporting files Added HTML template, styles, and configuration files
Comments suppressed due to low confidence (1)

cypress/e2e/spec-html.cy.js:1

  • All end-to-end Cypress tests for HTML functionality have been removed from spec-html.cy.js, including critical tests for localStorage blocking (authKey, OIDC keys), permission validation for external links, and internal link navigation. These behaviors should be covered by E2E tests to ensure the preview functionality works correctly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mwtrew mwtrew temporarily deployed to previews/1407/merge April 9, 2026 16:35 — with GitHub Actions Inactive
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 9, 2026 16:38 — with GitHub Actions Inactive
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 9, 2026 16:49 — with GitHub Actions Inactive
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 10, 2026 08:48 — with GitHub Actions Inactive
@zetter-rpf
Copy link
Copy Markdown
Contributor

zetter-rpf commented Apr 10, 2026

I was thinking about the seperate webpack config and tasks to run and build.

Is the intention to have the iframe deployed and served from the same bucket as editor-ui?
If it is, I wondered if there is value in having the seperate webpack config (instead of just a new entrypoint in the existing config). There is a benefit to having the iframe served from a different port in development, but it does add complexity to starting the server. Having the same config will still mean that we can test having the iframe on a separate port in development when included from standalone, it's only the local editor test page that won't be the same.

@mwtrew mwtrew temporarily deployed to previews/1407/merge April 10, 2026 13:10 — with GitHub Actions Inactive
@mwtrew mwtrew temporarily deployed to previews/1407/merge April 10, 2026 15:56 — with GitHub Actions Inactive
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.

3 participants