Fix gesture drag-drop dying when the <all_urls> permission is missing#20
Open
QingJ01 wants to merge 1 commit into
Open
Fix gesture drag-drop dying when the <all_urls> permission is missing#20QingJ01 wants to merge 1 commit into
QingJ01 wants to merge 1 commit into
Conversation
The gesture content script is registered based only on the "gesture.enabled" storage flag, but <all_urls> is an *optional* permission. registerContentScripts() succeeds even without the host permission, then injects into no page and drag silently does nothing. After a browser update reinstalls the system add-on, the optional <all_urls> grant can be reset while the flag stays true, leaving drag dead with no error. - Gate registration on BOTH the flag and permissions.contains(<all_urls>). - Re-sync registration on permissions.onAdded/onRemoved and storage changes. - Make registration idempotent (unregister-then-register) so a stale persisted registration is replaced instead of colliding with "already registered". - In options.js, write gesture.enabled=false to storage when <all_urls> is revoked, so the flag no longer desyncs from the permission/script state. Co-Authored-By: Claude <noreply@anthropic.com>
No Taskcluster jobs started for this pull requestThe |
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.
Problem
After a Firefox update, the gesture drag-and-drop feature (drag a link/image to open it in a new tab, drag text to search) silently stops working — no error, drag just does nothing. Other features keep working, which makes it look like a mysterious partial failure.
Root cause
<all_urls>is an optional permission (manifest.jsonoptional_permissions). The gesture content script is registered frombg/gestureDragDrop.jsbased only on thegesture.enabledstorage flag:But
browser.scripting.registerContentScripts({ matches: ["<all_urls>"], ... })succeeds even when the host permission isn't granted — it just injects into no page, so drag dies silently. After a browser update that reinstalls the system add-on, the optional<all_urls>grant can be reset whilegesture.enabledstaystrue→ the script stays "registered" but inert, and drag is dead with no error in the console.A second desync in
options/options.js: when<all_urls>is revoked it only doescheckbox.checked = false, which does not fire thechangeevent, sogesture.enabledis never written back tofalseand the background never unregisters the inert script.Fix
gesture.enabledandpermissions.contains(<all_urls>)via a newisGestureUsable()helper.syncScriptRegistration(), called on startup, onstorage.local.onChanged, and onpermissions.onAdded/permissions.onRemoved— so the script always reflects the real(flag ∧ permission)state.registerOrUnregisterScriptidempotent (unregister-then-register) so a registration persisted from a previous session is replaced instead of colliding with "already registered".options.js, writegesture.enabled = falseto storage when<all_urls>is revoked, so the flag no longer desyncs from the permission/script state.Scope / testing
Only
extension/bg/gestureDragDrop.jsandextension/options/options.jschange.npm run lint(eslintplugin:mozilla/recommended) passes.web-ext run: drag-and-drop works again after the fix.🤖 Generated with Claude Code