Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ notes. Entries describe what users experience, not internal refactors.
so language, GitHub and brand links remain reachable past the first screen.
- Nightly CI now runs the API surface, keyboard shortcut, and seeded monkey
sweeps (previously documented as nightly but never scheduled).
- Canvas PDF exports skip unnecessary PDF/A conversion for ordinary `.pdf`
downloads, reuse warm x2t worker fonts, and scale export timeouts by file size
([#317](https://github.com/ranuts/document/pull/317)).

### Removed

Expand All @@ -43,6 +46,17 @@ notes. Entries describe what users experience, not internal refactors.
- Read-only documents now look read-only: the toolbar keeps only the File and View tabs, editing buttons such as paste and macros are hidden, and the side panels are locked, while search, zoom and navigation stay available. Switching read-only off restores the full toolbar.
- Exporting a PDF or another format keeps unsaved changes in the editable original visible until the original is saved.
- Failed file opens restore usable file controls, including keyboard access.
- Legacy Office files with non-canonical OLE stream casing, East-Asian Word 95
FIB headers, malformed PPT slide persist IDs, broken embedded PNG color chunks,
or deeply nested DOCX tables now open instead of failing with `-82` or crashing
the renderer ([#313](https://github.com/ranuts/document/pull/313)).
- Window-level editor iframe guards now install synchronously before OnlyOffice
scripts execute, preventing spurious `-82` errors during recoverable open
retries ([#322](https://github.com/ranuts/document/pull/322),
[#323](https://github.com/ranuts/document/pull/323)).
- Landing-page idle prefetch preserves the `window` receiver when calling
`requestIdleCallback`, avoiding strict-mode `Illegal invocation` errors
([#321](https://github.com/ranuts/document/pull/321)).
- Document history search keeps focus and ignores outdated results while typing.
- Chat history conflicts offer an explicit way to keep local copies and restore saved conversations.
- Dictation reaching its time limit finishes normally and preserves the final recognized words.
Expand Down
86 changes: 52 additions & 34 deletions docs/changelogs/2026-12-04-ci-analytics-and-smoke-hardening.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,58 @@

Date: 2026-12-04 · PRs: [#316](https://github.com/ranuts/document/pull/316), [#319](https://github.com/ranuts/document/pull/319) · Upstream: [chaxus/ran#567](https://github.com/chaxus/ran/pull/567)

## Background

1. **Analytics spike**: Cloudflare analytics showed a recurring ~2.51k request spike at
04:00 CST caused by `Production smoke` running daily on a cron schedule against the live
site while executing real browser loads that fired GA4 and Cloudflare Web Analytics.
2. **Beacon SRI failure**: Fulfilling `cloudflareinsights.com` with an empty HTTP `204`
inside Playwright caused Chromium's Subresource Integrity check on `beacon.min.js` to
log `Failed to find a valid digest in the 'integrity' attribute`, turning
`Production smoke` red under L0 console checks.
3. **Semantic Pull Request `startup_failure`**: `.github/workflows/semantic-pull-request.yml`
triggered on `pull_request_target`, which failed before job startup on PRs in both
`ranuts/document` and `chaxus/ran`.

## Commits

| SHA | PR | Summary |
| ---------- | ---- | --------------------------------------------------------------------------------- |
| `3966698c` | #316 | Remove daily `prod-smoke` schedule and exclude E2E traffic from analytics |
| `af1d815b` | #319 | Abort Cloudflare beacon before SRI check and switch Semantic PR to `pull_request` |

## Key Changes

- **`.github/workflows/prod-smoke.yml`**: removed the daily `schedule` trigger (smoke now
runs on push to `main` and manual dispatch only).
- **`test/e2e/lib/l0.ts`**:
## 1. Context

1. Cloudflare Web Analytics showed a recurring ~2.51k request spike at 04:00 CST with no
corresponding organic user surge. Investigation traced it to
`.github/workflows/prod-smoke.yml`, which ran on a daily cron schedule against live
production while firing GA4 and Cloudflare analytics requests.
2. After `#316` intercepted analytics requests with HTTP `204`, `Production smoke` turned
red on `main` (run `#47254625679`) due to Chromium SRI verification failing on the
empty Cloudflare beacon script.
3. `.github/workflows/semantic-pull-request.yml` in both `ranuts/document` and
`chaxus/ran` was failing with `startup_failure` on every PR.

## 2. Thinking and evaluation

| Option | Decision | Reason |
| ------------------------------------------------------------------------------------------------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| Keep daily `prod-smoke.yml` cron and filter analytics only in Cloudflare dashboard | **Rejected** | Still wastes CI minutes and pollutes edge request counts every morning |
| Remove daily `schedule` from `prod-smoke.yml` (keep push-to-main + `workflow_dispatch`) and block analytics in Playwright | **Chosen** | Eliminates recurring fake traffic while preserving post-deploy verification |
| Fulfill `cloudflareinsights.com` with HTTP `204` | **Rejected** | Cloudflare injects `<script integrity="sha512-...">` for `beacon.min.js`; empty `204` fails Chromium SRI and trips L0 `console.error` |
| Abort `cloudflareinsights.com` with `route.abort('blockedbyclient')` and keep HTTP `204` for GA4 | **Chosen** | Cleanly prevents SRI check without tripping L0 console error assertions |
| Keep `pull_request_target` on `semantic-pull-request.yml` | **Rejected** | Caused `startup_failure` on PRs in both repos; title linting does not need base-branch secrets |
| Switch `semantic-pull-request.yml` trigger to `pull_request` | **Chosen** | Standard read-only trigger; works reliably on all PRs |

## 3. Approach

- `.github/workflows/prod-smoke.yml` (`3966698c`): removed daily `schedule` trigger.
- `test/e2e/lib/l0.ts` (`3966698c`, `af1d815b`):
- Tagged smoke browser `userAgent` with `RanutsProdSmoke/1.0`.
- Kept HTTP `204` interception for `googletagmanager.com` / `google-analytics.com`.
- Switched `cloudflareinsights.com` interception to `route.abort('blockedbyclient')` so
Chromium never runs SRI verification against an empty response body.
- **`.github/workflows/semantic-pull-request.yml`**: changed trigger from
`pull_request_target` to `pull_request` (mirrored in `chaxus/ran#567`, plus updating
`bin/test/workflows.test.ts`).
- Fulfilled `googletagmanager.com` and `google-analytics.com` with HTTP `204`.
- Aborted `cloudflareinsights.com` with `route.abort('blockedbyclient')`.
- `.github/workflows/semantic-pull-request.yml` (`af1d815b`): switched `on: pull_request_target`
to `on: pull_request`.

## Verification
## 4. Problems and fixes

- `Production smoke` on `main` turned green (`success`) immediately after `#319` merged.
- `Semantic Pull Request` passed normally on subsequent PRs in both repositories.
1. **Cloudflare beacon SRI failure after `#316`**: fulfilling `cloudflareinsights.com`
with HTTP `204` triggered `Failed to find a valid digest in the 'integrity' attribute`
in Chromium, failing L0 on `Production smoke`. **Fix (`#319`, `test/e2e/lib/l0.ts`)**:
switched `cloudflareinsights.com` to `route.abort('blockedbyclient')`.
2. **Workflow contract test in `chaxus/ran`** (`bin/test/workflows.test.ts`): removing the
last `pull_request_target` workflow tripped `assert.ok(targets.length > 0)`. **Fix
(`chaxus/ran#567`)**: asserted `workflows.length > 0` while preserving the concurrency
guard for any future `pull_request_target` workflow.

## 5. Verification

- Local: `vitest run test/unit/workflow-contract.test.ts` (71/71 passed),
`oxlint --deny-warnings`, `prettier --check`.
- Remote CI: `#316` (18/18) and `#319` (19/19) passed and rebased onto `main`.
- Post-merge: `Production smoke` on `main` succeeded consecutively after `#319`;
`Semantic Pull Request` passed on `#319` and all subsequent PRs.

## 6. Leftovers

- None.
95 changes: 68 additions & 27 deletions docs/changelogs/2026-12-04-editor-frame-pre-vendor-bootstrap.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,70 @@
# Pre-vendor editor frame bootstrap

Previously, all editor iframe guards (`installOpenFailureGuard`, `shadowSharedWorker`,
`installUnloadPagehide`, `injectLocalChromeCss`, and the SDK-specific hooks) were
installed from the host page via `prepareEditorIframe()` starting at `onAppReady` and
re-polled on a timer. Any guard that needed to claim a `window`-level hook before
OnlyOffice's own scripts executed raced the iframe boot sequence: under CI or slow-device
load, `sdk-all-min.js` could register its `onunhandledrejection` handler first and emit a
spurious `asc_onError(-82)` before our guard's `stopImmediatePropagation()` ran (because
WHATWG DOM dispatches `unhandledrejection` at `AT_TARGET` in registration order regardless
of `capture`).

## Changes

- Added a minimal synchronous pre-vendor bootstrap script
`public/web-apps/apps/common/editor-frame-bootstrap.js` loaded as the very first
`<script>` in `<head>` of all four editor entry pages (`documenteditor`,
`spreadsheeteditor`, `presentationeditor`, `pdfeditor`).
- Exported `bootstrapEditorFrame(win)` and `registerEditorFrameBootstrapHost()` from
`lib/onlyoffice/iframe-guards.ts`, registering the host bridge in
`lib/onlyoffice-editor.ts` before constructing `DocsAPI.DocEditor`.
- Window-level guards (`installOpenFailureGuard`, `shadowSharedWorker`,
`installUnloadPagehide`, `injectLocalChromeCss`) now execute synchronously inside the
editor iframe before any vendor script parses or runs, eliminating the registration-order
race for both `onunhandledrejection` and `addEventListener('unhandledrejection')`.
- `prepareEditorIframe()` remains idempotent for post-SDK hooks (`AscCommon.x2t`,
`DrawingDocument`, save semantics, font loading) and as a fallback.
- Pinned the `<head>` script-order contract in `test/unit/vendor-contract.test.ts` and
added `test/unit/editor-frame-bootstrap.test.ts`.
Date: 2026-12-04 · PR: [#323](https://github.com/ranuts/document/pull/323) · Commit: `69c1fc3c`

## 1. Context

All 18 editor iframe guards in `lib/onlyoffice/iframe-guards.ts` were previously applied
from the host page via `prepareEditorIframe()`, which only started running at `onAppReady`
and re-polled on a 200 ms interval. Any guard that needed to claim a `window`-level hook
before OnlyOffice's own scripts executed (`unhandledrejection`, `error`, `SharedWorker`,
`onunload`) inherently raced the iframe's synchronous `<script>` boot sequence.

Related prior entries:

- [2026-10-17-open-retry-reporting.md](./2026-10-17-open-retry-reporting.md)
- [2026-12-04-ranuts-0.5.7-dedup-and-hardening.md](./2026-12-04-ranuts-0.5.7-dedup-and-hardening.md) (`#322`)

## 2. Thinking and evaluation

| Option | Decision | Reason |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Rely solely on `#322` (`re-seat win.onunhandledrejection` during `onAppReady` poll) | **Deferred (kept as defense-in-depth)** | Fixes current `onunhandledrejection` race, but would miss early boot errors before `onAppReady` or a future OnlyOffice switch to `addEventListener('unhandledrejection')` |
| Patch vendor `sdk-all-min.js` directly | **Rejected** | High maintenance cost on OnlyOffice upgrades |
| Inject an inline `<script>` into the 4 editor `index.html` files | **Rejected** | Requires updating CSP SHA-256 hashes whenever the snippet changes |
| Load an external same-origin `<script src="../../common/editor-frame-bootstrap.js">` as the first `<script>` in `<head>` of all 4 editor `index.html` files | **Chosen** | Works under both `/` and GitHub Pages `/document/`, satisfies `script-src 'self'` without CSP hash churn, cached by `sw.js` under `/web-apps/`, and guarantees HTML parser execution order before all vendor scripts |

## 3. Approach

- Created `public/web-apps/apps/common/editor-frame-bootstrap.js`: synchronous 10-line IIFE
that calls `window.parent.__ooBootstrapEditorFrame(window)` inside a `try/catch`
(cross-origin safe).
- Added `<script src="../../common/editor-frame-bootstrap.js"></script>` immediately after
`<title>` (strictly before all vendor `<script>` tags) in:
- `public/web-apps/apps/documenteditor/main/index.html`
- `public/web-apps/apps/spreadsheeteditor/main/index.html`
- `public/web-apps/apps/presentationeditor/main/index.html`
- `public/web-apps/apps/pdfeditor/main/index.html`
- `lib/onlyoffice/iframe-guards.ts`: exported `bootstrapEditorFrame(win)` (runs
`installOpenFailureGuard`, `shadowSharedWorker`, `installUnloadPagehide`,
`injectLocalChromeCss` synchronously) and `registerEditorFrameBootstrapHost()`.
- `lib/onlyoffice-editor.ts`: calls `registerEditorFrameBootstrapHost()` immediately
before constructing `DocsAPI.DocEditor`.
- `test/unit/vendor-contract.test.ts`: pinned that `editor-frame-bootstrap.js` exists and
is the first `<script` tag in all 4 editor entry HTML files.
- `test/unit/editor-frame-bootstrap.test.ts`: executes the real bootstrap script against a
standard WHATWG `EventTarget` frame to verify pre-vendor guard installation and
`AT_TARGET` precedence even over `addEventListener('unhandledrejection')`.

## 4. Problems and fixes

1. **Multi-app coverage**: initially considered only Word/Cell/Slide (`documenteditor`,
`spreadsheeteditor`, `presentationeditor`); checking `vendor-contract.test.ts` revealed
`pdfeditor/main/index.html` uses the same layout. **Fix**: wired all 4 apps and pinned
all 4 in `vendor-contract.test.ts`.
2. **Base-path portability**: hardcoded `/editor-frame-bootstrap.js` would 404 on GitHub
Pages `/document/`. **Fix**: placed under `public/web-apps/apps/common/` and referenced
via relative `../../common/editor-frame-bootstrap.js`.

## 5. Verification

- Local: `vitest run test/unit/editor-frame-bootstrap.test.ts test/unit/vendor-contract.test.ts test/unit/onlyoffice-editor.test.ts test/unit/onlyoffice-open-failure.test.ts`
— 4/4 files, 127/127 passed; `oxlint --deny-warnings` 0 warnings/errors; `prettier --check`
passed.
- Remote CI: all checks passed and auto-rebased onto `main`.

## 6. Leftovers

- SDK-dependent guards (`AscCommon.x2t`, `DrawingDocument`, `fetchFonts`, save semantics)
intentionally remain on `prepareEditorIframe()` because those vendor globals do not
exist at `<head>` parse time.
Loading
Loading