Skip to content

Improve host permission handling and error reporting - #4

Merged
jbtronics merged 1 commit into
mainfrom
ccr-9f73d339-c7z9qy
Nov 14, 2026
Merged

jbtronics merged 1 commit into
mainfrom
ccr-9f73d339-c7z9qy

Conversation

@jbtronics

Copy link
Copy Markdown
Member

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() to requestHostPermissions() to accept multiple URLs at once, reducing redundant permission requests when saving multiple hosts. The function now deduplicates origins and requests them in a single chrome.permissions.request() call.

  • Added host permission utilities: Created hostPermissionPattern() and hasHostPermission() functions in host-storage.js to 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 specific missing_host_permission error code.

  • Better error messages:

    • Added user-friendly error message when host permissions are missing, guiding users to re-grant permissions via settings
    • Added error message for permission request failures with the underlying error details
    • Updated popup error handling to display the new missing permission error message
  • 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

  • Permission requests are now synchronized from user input handlers before any await statements, as required by Firefox's permission API
  • Origins are deduplicated using Set to avoid redundant permission requests
  • Error handling includes try-catch for the chrome.permissions.request() call to gracefully handle permission API failures
  • The batch permission request in saveAllSettings() only executes if there are new hosts to add

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
@jbtronics
jbtronics merged commit 2014a05 into main Nov 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants