Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declaring compatible websites (without prompting the user) #700

Open
fregante opened this issue Sep 28, 2024 · 3 comments
Open

Declaring compatible websites (without prompting the user) #700

fregante opened this issue Sep 28, 2024 · 3 comments
Labels
needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: firefox Firefox needs to assess this issue for the first time supportive: safari Supportive from Safari

Comments

@fregante
Copy link

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.

@github-actions github-actions bot added needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: firefox Firefox needs to assess this issue for the first time needs-triage: safari Safari needs to assess this issue for the first time labels Sep 28, 2024
@fregante fregante changed the title Declaring compatible websites and optional content script injection Declaring compatible websites (without prompting the user) Sep 28, 2024
@xeenon
Copy link
Collaborator

xeenon commented Sep 28, 2024

I think most browsers are on a path to do what Safari does today with host_permissions, so this new key might not be needed. I'm supportive though, if others think it is worth doing as a separate key.

@xeenon xeenon added supportive: safari Supportive from Safari and removed needs-triage: safari Safari needs to assess this issue for the first time labels Sep 28, 2024
@fregante
Copy link
Author

I think most browsers are on a path to do what Safari does today with host_permissions

Chrome's first draft for MV3 intended to do that already1, but they changed their mind at some point. I'm not sure they want to revisit the default behavior just yet, probably not before MV4 anyway.

if others think it is worth doing as a separate key

If adding more "host" arrays is undesirable, these two behaviors could still be locked in via options. I want to reiterate that the problem here is specifically the lack of consistency and choice in how these permissions are presented to the user. Perhaps:

  • grant_host_permissions: boolean - true by default; Safari only supports false

When set to false, this also withholds the permissions granted via content_scripts.*.matches and allows the removal via permissions.remove()

As for the second behavior, honestly I just wish Safari and Firefox stopped showing this button/toggle, because that's not what I mean when I specify optional_host_permissions: ["*://*/*"]:

371737256-e2d1c388-2b6e-44c0-980d-60469fc9bfc6 371737259-d7906526-0c4f-4862-ae31-5111eb5f3362

If you want to keep them, then I'd love to see an option to hide it:

  • propose_all_urls: boolean - true by default; not applicable to Chrome at the moment

Footnotes

  1. Quote from the document: Since host permissions are going to require runtime approval by the user, they will not need a separate optional_host_permissions entry (whether such permissions will be removable via the permissions.remove API method is TBD.)

@fregante
Copy link
Author

fregante commented Sep 29, 2024

Note that this set up would allow something really cool:

{
	"name": "Dark mode on demand",
	"manifest_version": 3,
	"grant_host_permissions": false,
	"propose_all_urls": false,
	"content_scripts": [{
		"matches": ["*://*/*"],
		"css": ["darkmode.css"]
	}]
}

Specifically:

  1. no permissions requested on install1
  2. no prompting to enable the extension on specific sites (no badges, no popups)
  3. host permission management UI provided by the browser2
  4. content script injection safely managed by the browser

The best part is that every browser already has this logic and UI built in, it's just not exposed evenly.

Footnotes

  1. Screenshot
  2. Screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: firefox Firefox needs to assess this issue for the first time supportive: safari Supportive from Safari
Projects
None yet
Development

No branches or pull requests

2 participants