Skip to content

fix(embed): send document buffer as base64 to avoid ArrayBuffer loss in embedded WebViews (#113) - #115

Open
chaxus wants to merge 1 commit into
mainfrom
fix/issue-113-embed-buffer-base64
Open

fix(embed): send document buffer as base64 to avoid ArrayBuffer loss in embedded WebViews (#113)#115
chaxus wants to merge 1 commit into
mainfrom
fix/issue-113-embed-buffer-base64

Conversation

@chaxus

@chaxus chaxus commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • document:open-buffer had no support for base64-encoded payloads, the only transport a host like Qt WebEngine's runJavaScript() can use to hand over binary data (JSON-only bridge).
  • asc_openDocument sent the converted document buffer as a raw ArrayBuffer/Uint8Array through OnlyOffice's internal editor iframe via postMessage, which relies on the host's structured-clone support for binary types. Some embedded WebViews (reported: Qt WebEngine / PySide6) appear to lose that data in transit, which OnlyOffice's engine then can't recognize and reports as a format mismatch (errorCode -85).
  • Send the buffer as a base64 string instead, mirroring the already-working "new document" empty-template path (lib/empty_bin.ts), which sidesteps ArrayBuffer structured-clone entirely since strings always survive postMessage.
  • Added base64 decoding support to document:open-buffer payloads (with optional data:...;base64, prefix stripping).

Full root-cause writeup: docs/explorations/2026-08-04-issue-113-embed-buffer-format-mismatch.md.

Caveat

I don't have a Qt WebEngine environment to reproduce this end-to-end, so this fix is based on static analysis of the vendored OnlyOffice SDK + the working "new document" precedent, not a confirmed live repro. All existing behavior (real browsers, the empty-template path) is unit-tested and unchanged.

Test plan

  • pnpm run lint:ts (oxlint + tsc)
  • pnpm run format:check
  • pnpm run test:coverage — 263 tests pass, incl. 4 new cases covering base64 payload decoding and the asc_openDocument buf format
  • @zjhtsgr — could you try this branch in your Qt WebEngine setup and confirm it opens the docx correctly?

Closes #113 (pending confirmation).

🤖 Generated with Claude Code

…in embedded WebViews (#113)

document:open-buffer had no support for base64-encoded payloads, the
only transport a host like Qt WebEngine's runJavaScript() can use to
hand over binary data. Separately, asc_openDocument sent binData as a
raw ArrayBuffer through OnlyOffice's internal iframe postMessage,
which relies on the host's structured-clone support for binary types.
Send it as base64 instead, mirroring the already-working empty
"new document" template path, which sidesteps that dependency
entirely.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying document with  Cloudflare Pages  Cloudflare Pages

Latest commit: 18bb045
Status: ✅  Deploy successful!
Preview URL: https://b4dfe7f8.document-7hm.pages.dev
Branch Preview URL: https://fix-issue-113-embed-buffer-b.document-7hm.pages.dev

View logs

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.

[BUG] document:open-buffer 无法打开 docx 文件,错误码 -85

1 participant