Repository navigation
fix(editor): stop stubbing the preview Service Worker registration - #165
Merged
Merged
Conversation
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
Contributor
Preview this PR in the Nextcloud PlaygroundA fresh Nextcloud boots in your browser with this branch's eXeLearning editor: |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
EditorHtmlServicereplacednavigator.serviceWorker.registerwith a stub, so the editor never got its preview Service Worker: the inline preview fell back toblob: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.jsthrough to the realnavigator.serviceWorker.registerand 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 theblob: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 inADR-165-01.Verification
EditorHtmlServiceTest::testInjectsBaseConfigResilienceAndSaveBridgenow asserts that the injected script does not assignserviceWorker.register: red before the change, green after. PHPUnit: 120 tests passed.php-cs-fixer --dry-run: nothing to fix.make up), before the change: no preview worker, inline preview on ablob:URL, Fullscreen opens nothing.…/custom_apps/exelearning/js/editor/viewer/and Fullscreen opens…/custom_apps/exelearning/js/editor/viewer/index.html?exe-teacher=1with the resource:Notes
blob:preview, as before.Follow-up review
EditorHtmlServiceTest::testLetsOnlyThePreviewWorkerRegisterchecks the forwarding and the rejection and catches bracket,definePropertyand prototype overrides.Refsinstead ofCloses: 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.window.openerpointing at the editor. The inlineblob:preview already ran the same content on the same origin, so this lowers defence in depth rather than adding a privilege./viewer/path.