Fix web extension load on locked devices + lighter burn reload#5235
Open
miasma13 wants to merge 6 commits into
Open
Fix web extension load on locked devices + lighter burn reload#5235miasma13 wants to merge 6 commits into
miasma13 wants to merge 6 commits into
Conversation
…in-memory parsed extension instead of re-reading from disk on every burn
… avoid InvalidArchive errors on locked devices, with deferral/resume pixels
…oadInstalledExtensions
Contributor
|
Privacy Review task: https://app.asana.com/0/69071770703008/1215338943121945 |
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 61f4337. Configure here.
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.

Task/Issue URL: https://app.asana.com/1/137249556945/project/414709148257752/task/1215332334414209?focus=true
Tech Design URL: N/A
CC:
Description
Two related web-extension issues on iOS (both gated behind iOS 18.4 + the
webExtensionsfeature flag).1. Lightweight reload on data clear (fire). Every fire unloaded all web extensions and then ran the full
loadInstalledExtensions(), which re-reads and re-parses each extension archive from disk (WKWebExtension(resourceBaseURL:)) plus install-store reads and orphaned-file cleanup — even though the installed set never changes during a burn. NewreloadInstalledExtensions()reuses the already-parsedWKWebExtensioncaptured at unload time, keeping only thecontroller.unload/loadcycle that resets background-page in-memory state. Wired on both iOS and macOS; falls back to a full load if nothing is cached or a reload throws.2.
WKWebExtensionErrorInvalidArchive(domain code 9), ~400/day on iOS. The on-disk extension archive was being read byWKWebExtension(resourceBaseURL:)while protected data was unavailable (device locked / before first unlock), so the read failed. It surfaced on both load and install because both construct the extension from the same stored artifact (and a failed load auto-uninstalls, so the follow-up reinstall fails too — a cascade). Fix: gate both the load (scheduleExtensionLoad) and install/sync (syncEmbeddedExtensions) onUIApplication.shared.isProtectedDataAvailable; when unavailable, defer the work and replay it once onprotectedDataDidBecomeAvailableNotification. macOS has no file data protection, so this gate is iOS-only.Two temporary pixels are added to measure the frequency of this fallback:
m_web_extension_deferred_protected_data_unavailable— fires when web-extension load/install is postponed because protected data isn't readable yet (device locked / before first unlock), i.e. the situation that previously produced the WKWebExtensionErrorInvalidArchive (code 9) errors.m_web_extension_resumed_protected_data_available— fires when protected data becomes available and that deferred load/install actually runs.Testing Steps
Prerequisites
Steps
▎ Steps 5–6 are the core check: each Fire unloads the web extensions and re-runs the lightweight reloadInstalledExtensions(), so the ad-blocking and autoconsent (embedded) extensions must reload and function correctly after every burn — with no degradation across repeated Fires.
Impact and Risks
Medium — changes web-extension load/install timing on the fire and launch paths. Blast radius limited to users on iOS 18.4+ with the
webExtensionsfeature flag enabled.What could go wrong?
protectedDataDidBecomeAvailableNotificationnever fired, deferred load/install could stay pending until the next launch. Mitigated: the gate only defers when protected data is genuinely unavailable, a normal unlock posts the notification, and teardown clears any pending work.loadInstalledExtensions()on an empty cache or any reload failure, and feature-flag-driven installs run a full sync separately.Quality Considerations
m_web_extension_deferred_protected_data_unavailableandm_web_extension_resumed_protected_data_available— to confirm code-9 errors drop and deferrals recover.reloadInstalledExtensions(lightweight path, empty-cache fallback, failure fallback).Notes to Reviewer
MainCoordinator/PixelEventbuild clean) — a full app build only trips on environmental headless-CLI script phases (codesign identity, simulatorTARGET_DEVICE_OS_VERSION), unrelated to these changes.Internal references:
Definition of Done | Engineering Expectations | Tech Design Template
Note
Medium Risk
Changes web extension load timing on fire and cold launch (iOS 18.4+ with web extensions enabled); mitigated by full-load fallback and unlock notification replay, but deferred work could linger if protected-data notifications never fire.
Overview
Adds a fire/data-clear reload path that reuses in-memory
WKWebExtensioninstances captured duringunloadAllExtensions()instead of re-reading archives from disk. NewreloadWebExtensionon the loader andreloadInstalledExtensions()on the manager wire this into iOS and macOS burn completion (replacingloadInstalledExtensions()), with fallback to a full load when the cache is empty or any lightweight reload fails.On iOS only, extension startup load and embedded-extension sync now wait until
UIApplication.shared.isProtectedDataAvailable, deferring work via coalesced callbacks onprotectedDataDidBecomeAvailableto avoidWKWebExtensionErrorInvalidArchivewhen Application Support is unreadable while the device is locked.Adds daily pixels for deferral/resume and unit tests for the reload fallbacks and lightweight path.
Reviewed by Cursor Bugbot for commit 61f4337. Bugbot is set up for automated code reviews on this repo. Configure here.