fix: ServiceWorker job queue persistence and cross-page progress display - #124
Open
enhk2728-ui wants to merge 1 commit into
Open
enhk2728-ui wants to merge 1 commit into
enhk2728-ui wants to merge 1 commit into
Conversation
The task service had several architectural issues in its MV3 ServiceWorker
context that prevented the progress bar from appearing after creating a
backup job:
Root causes fixed:
1. Queue persistence saved Promises instead of Jobs (service.js)
- toJSON() was serializing _jobQueue.promises (internal Promise
objects), which are not serializable — this broke session restore.
- Fix: serialize _jobQueue.queuedItems (actual Job objects with
proper toJSON()) and deserialize with Job.fromJSON().
2. AsyncBlockingQueue lacked item tracking (AsyncBlockingQueue.js)
- Added _queuedItems[] array that mirrors enqueue/dequeue operations.
- Added queuedItems getter for serializable queue state access.
3. Task.step() did not trigger progress events (Task.js)
- Task now extends EventTarget and dispatches 'taskstep' event on
each step() call, enabling real-time progress bar updates.
4. Job did not forward task progress to Service (Job.js)
- Job.run() now listens to taskstep events on each task and forwards
them as Service progress events to refresh the UI.
5. Page navigation destroyed the Service context (backup.js)
- Creating a job then immediately jumping to options.html destroyed
the backup.html page's Service instance (MV3 isolated contexts).
- Fix: added ServicePanelInline class that displays task progress
directly in backup.html without page navigation.
6. Cross-page progress awareness via storage.onChanged (options.js)
- ServicePanel now monitors chrome.storage.onChanged for session
state updates from other pages, enabling options.html to show
progress even when the job runs from a different page context.
Co-Authored-By: Claude <noreply@anthropic.com>
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.
Summary
This PR fixes an architectural issue in the MV3 ServiceWorker task service that prevented the progress bar from appearing after creating a backup job — known as the "新建任务后看不到进度条" (progress bar invisible after creating new task) problem.
Root Cause Analysis
The task service (
Service) was being instantiated independently in each Chrome extension page context (backup.html,options.html,background.js). In Manifest V3, each page has its own isolated JavaScript context, soService._instancewas not shared between them.When a user clicked "新建任务" in
backup.html:backup.htmlpage's Service instanceoptions.html#servicevialocation.hrefbackup.htmlpage context — along with its Service instance and the enqueued joboptions.htmlloaded its own Service instance, which had nocurrentJob— so the progress table rendering returned earlyAdditionally, the session state persistence was broken:
service.toJSON()was saving_jobQueue.promises(internal Promise objects fromAsyncBlockingQueue) which are not serializableservice.fromJSON()was trying to restore queue items viataskFromJSON()instead ofJob.fromJSON()Task.step()only incremented a counter but never fired UI refresh eventsChanges
1.
services/AsyncBlockingQueue.js_queuedItems[]array that tracks actual data objects (not internal Promises)enqueue()pushes items to_queuedItems;dequeue()removes them once consumedqueuedItemsgetter for serialization2.
service.jstoJSON()now serializes_jobQueue.queuedItems(real Job objects viajob.toJSON()) instead of internal Promise objectsfromJSON()now restores queue usingJob.fromJSON()instead oftaskFromJSON()3.
services/Task.jsTasknow extendsEventTarget(not just a plain class)step()dispatches a'taskstep'event so consumers can react to progress changes4.
services/Job.jsJob.run()now listens to each task'staskstepevent and forwards it as a Serviceprogressevent5.
backup.jslocation.href = ...) after creating a job, the page now stays inbackup.htmland renders an inline progress panel (ServicePanelInline)6.
options.jsServicePanelnow monitorschrome.storage.onChangedfor session state updatesbackup.html) saves updated Job state,options.htmlrenders it from the stored JSON_renderFromStoredJob()to render progress from serialized Job data_renderTasks()helper for cleaner code reuseTesting
These changes have been verified in a local extension build. The workflow:
backup.html)Related Issues
Fixes the "新建任务后看不到进度条" regression introduced by the MV3 migration.