Skip to content

CST-5609: Stop the Prepublish frame from taking over the editor's tab - #75

Open
rdom-si wants to merge 2 commits into
masterfrom
fix/CST-5609-contain-prepublish-frame
Open

rdom-si wants to merge 2 commits into
masterfrom
fix/CST-5609-contain-prepublish-frame

Conversation

@rdom-si

@rdom-si rdom-si commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes the remaining Prepublish failure in CST-5609. On the customer's site, clicking Prepublish replaced the editor's preview with the si_preview_nonce copy of the page. Our scripts are excluded on that URL, so the overlay vanished and no check was sent. The likely cause is a theme or security plugin script that reloads itself as the top-level page when it detects a frame.

 getDom(nonce)
   iframe#domIframe
+    sandbox="allow-same-origin allow-scripts"   # no allow-top-navigation: framed page can't navigate the tab
-    style="height:100vh; width:100%"            # visible, looked like a new page opening
+    style="position:fixed; ... opacity:0; pointer-events:none"
+    aria-hidden="true" tabindex="-1" title="Siteimprove Prepublish"
   load -> read contentWindow.document           # unchanged; allow-same-origin keeps it readable

allow-scripts is kept so script-rendered content is still captured as before. The frame keeps a full viewport so the page lays out the same.

Evidence

New browser tests in tests/browser/prepublish.spec.js, run for both the toolbar and overlay entry points:

a page that reloads itself out of frames cannot take over the browser tab
  given a preview whose script does `top.location = self.location` when framed
  start Prepublish
  expect draft content handed over, editor URL unchanged, frame cleaned up

the temporary frame is hidden from the editor while it loads
  expect #domIframe opacity 0, pointer-events none, aria-hidden, tabindex -1
  • Before: all 4 new tests fail. The takeover test reproduces the customer symptom: the top page navigates away and window._si is gone (Cannot read properties of undefined (reading 'some')).
    After: all 25 browser tests pass locally in Chrome.

Not run locally: Firefox and the WordPress/multisite suites (the test browser and WordPress downloads time out from my machine). CI covers both.

Merge Danger

Door: two-way

A single JS change; revert restores 2.1.4 behaviour.

Blast Radius: Prepublish

The sandbox applies to the framed page only. Inside it, popups, form submission, alert/confirm and top navigation are blocked. None are needed to read the DOM, but a site that renders content only after one of them would capture differently. A test build (2.1.5-beta.1) is going to the customer's dev environment to confirm the fix before release.

Some themes and security plugins reload themselves as the top-level page
when framed. That replaced the editor's preview with the si_preview_nonce
copy, where our scripts are excluded, so the check never ran.

Sandbox the frame without allow-top-navigation, and make it invisible and
inert so editors see the loading indicator instead of a second page.
@rdom-si
rdom-si requested a review from a team as a code owner November 4, 2026 22:44

This branch has not been deployed

No deployments
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.

2 participants