Skip to content

fix(editor): stop stubbing the preview Service Worker registration - #165

Merged
erseco merged 4 commits into
mainfrom
hotfix/2776-fullscreen-preview-service-worker
Dec 1, 2026
Merged

erseco merged 4 commits into
mainfrom
hotfix/2776-fullscreen-preview-service-worker

Conversation

@erseco

@erseco erseco commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Refs exelearning/exelearning#2776 (close it once the bundled editor includes exelearning/exelearning#2771)

Problem

In the embedded editor the inline preview works, but the Fullscreen (open in new tab) button of the preview panel does nothing. The resilience script injected by EditorHtmlService replaced navigator.serviceWorker.register with a stub, so the editor never got its preview Service Worker: the inline preview fell back to blob: URLs and the new-tab preview, which is only served by the worker, bailed out with "Service Worker not available for preview".

Fix

Pass only preview-sw.js through to the real navigator.serviceWorker.register and reject every other script, so the editor's offline PWA worker (service-worker.js) stays out of Nextcloud. The editor catches the rejection and falls back to the blob: preview. The app's own package runtime worker is registered from the viewer page and is not affected. The fetch and jQuery 404 fallbacks are unchanged. Decision recorded in ADR-165-01.

Verification

  • EditorHtmlServiceTest::testInjectsBaseConfigResilienceAndSaveBridge now asserts that the injected script does not assign serviceWorker.register: red before the change, green after. PHPUnit: 120 tests passed. php-cs-fixer --dry-run: nothing to fix.
  • Manual check on a local Nextcloud (make up), before the change: no preview worker, inline preview on a blob: URL, Fullscreen opens nothing.
  • After the change: the worker registers with scope …/custom_apps/exelearning/js/editor/viewer/ and Fullscreen opens …/custom_apps/exelearning/js/editor/viewer/index.html?exe-teacher=1 with the resource:

nextcloud-after.png

Notes

Follow-up review

  • Registration is filtered instead of left untouched (PWA worker rejected).
  • EditorHtmlServiceTest::testLetsOnlyThePreviewWorkerRegister checks the forwarding and the rejection and catches bracket, defineProperty and prototype overrides.
  • Refs instead of Closes: Fullscreen opens the right path only once the bundled editor includes fix(preview): open the fullscreen preview under the embedding base path (#2770) exelearning#2771.
  • The new tab renders package HTML/JS top-level on the site origin, served by the editor's worker, without the content proxy's CSP, and with window.opener pointing at the editor. The inline blob: preview already ran the same content on the same origin, so this lowers defence in depth rather than adding a privilege.
  • Known upstream editor limitations, not fixed here: the preview worker keeps one content map for all tabs in its scope, so two editor tabs with the preview open can show each other's project; and the new tab does not reload on edits because the injected reload script only matches a root /viewer/ path.

The editor serves its new-tab (fullscreen) preview only through its preview
Service Worker. The resilience script replaced navigator.serviceWorker.register
with a stub, so the inline preview fell back to blob: URLs and the Fullscreen
button did nothing. The editor handles a rejected registration by itself (it
falls back to the blob: preview), so the stub is no longer needed.

Closes exelearning/exelearning#2776
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Preview this PR in the Nextcloud Playground

Open this PR in the Nextcloud Playground

A fresh Nextcloud boots in your browser with this branch's exelearning app installed and enabled (log in as admin / admin). Two sample .elpx are seeded under exelearning-samples/ in Files — click one to open the viewer.

eXeLearning editor: v4.0.6 (overlaid at boot from the upstream release).

@codecov-commenter

codecov-commenter commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.75%. Comparing base (d9d955c) to head (76c3f0a).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main     #165   +/-   ##
=========================================
  Coverage     93.75%   93.75%           
  Complexity      154      154           
=========================================
  Files            27       27           
  Lines           801      801           
  Branches         92       92           
=========================================
  Hits            751      751           
  Misses           36       36           
  Partials         14       14           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Forward preview-sw.js to the real navigator.serviceWorker.register and
reject every other script, so the editor's offline PWA worker stays out of
Nextcloud while the Fullscreen preview gets its worker. The editor catches
the rejection and uses the blob: preview. The test now checks the
forwarding and the rejection, and catches defineProperty, bracket or
prototype overrides. Record the decision in ADR-165-01.
@erseco
erseco merged commit 3f68162 into main Dec 1, 2026
20 checks passed
@erseco
erseco deleted the hotfix/2776-fullscreen-preview-service-worker branch December 1, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants