Repository navigation
Improve host permission handling and error reporting - #4
Merged
Merged
Conversation
Firefox does not support port numbers in host permission match patterns, so the requested pattern (e.g. http://192.168.1.10:8080/*) never matched and all requests failed with "NetworkError when attempting to fetch resource". Request the permission for the host without port instead, which works in both Chrome and Firefox. Also request permissions for all configured instances in a single permissions.request() call, as Firefox only allows it directly inside a user input handler, and show a clearer error in the popup when host permission is missing. See Part-DB/Part-DB-server#1525 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017TWRopcP8FAsxdixm9p4Hu
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 improves the extension's host permission handling by refactoring permission requests to be batch-processed, adding better error detection for missing permissions, and providing more actionable error messages to users.
Key Changes
Refactored permission request logic: Renamed
requestHostPermission()torequestHostPermissions()to accept multiple URLs at once, reducing redundant permission requests when saving multiple hosts. The function now deduplicates origins and requests them in a singlechrome.permissions.request()call.Added host permission utilities: Created
hostPermissionPattern()andhasHostPermission()functions inhost-storage.jsto centralize host permission pattern generation and checking. The pattern deliberately omits ports since Firefox doesn't support them in match patterns.Improved error detection: Added
networkErrorResult()helper in the service worker that detects when network errors are caused by missing host permissions (rather than actual network failures) and returns a specificmissing_host_permissionerror code.Better error messages:
Updated documentation: Clarified in README that host permissions are scoped to hosts (all ports) rather than specific URLs, explaining Firefox's port limitation.
Implementation Details
awaitstatements, as required by Firefox's permission APISetto avoid redundant permission requestschrome.permissions.request()call to gracefully handle permission API failuressaveAllSettings()only executes if there are new hosts to add