Skip to content

Declaring compatible websites (without prompting the user) #700

@fregante

Description

@fregante

Problem

The current optional host permission situation has a few inconsistencies and limitations across browsers. Here are some:

  • Safari does not grant host_permissions on install
  • "all sites" optional permissions are generally treated as an invite to enable the extension on "all sites" at once1
  • offering "optional content scripts" requires manually dealing with permission grants and content script registration2

Proposal: "suggested hosts" and "available hosts"

These issues could be resolved with two additional well-defined top-level keys for the manifest. These two keys could replace (or be preferred to) host_permissions, optional_host_permissions and content_script.*.matches

suggested_hosts

  • no permissions granted on install
  • the browser will eventually prompt the user via badges (Firefox screenshot) and popups (Safari screenshot)
  • the author can use permissions.request() and permissions.remove()

This is exactly how Safari currently treats host_permissions.

available_hosts

Like optional_host_permissions, but:

  • the browser never prompts the user in any way
  • the browser does not show a "enable on all sites" button/toggle

Example

This extension would show "No permissions requested" on install, then show a badge when the user visits YouTube. Optionally the user can enable the extension on any website that might be compatible.

{
	"name": "Watch History Collector",
	"description": "Tracks the titles of watched videos",
	"manifest_version": 3,
	"suggested_hosts": [
		"https://youtube.com",
		"https://vimeo.com",
	],
	"available_hosts": [
		"*://*/*"
	],
	"background": {
		"service_worker": "background.js"
	}
}

Follow-up for Safari

Safari does not support host_permissions the way it was defined, so they should mark the key as "Not supported; aliased to suggested_hosts"

Footnotes

  1. Safari shows an "Always Allow on Every Website…" button (screenshot); Firefox has a toggle (screenshot) that is a footgun (support requests)

  2. Safari effectively allows this via plain content_script.*.matches='*://*/*, but the user is presented with "The extension wants to access this site" rather than "The extension is available for this site". My solution for this has been my webext-dynamic-content-script package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions