Skip to content

Lesson 2 of 9 · 22m

The Permissions Model and User Consent

Permissions are a product surface, not a checklist. Model host access, optional permissions, and activeTab around actual user intent.

Permission prompts are the first security review your users perform, and they perform it with their thumbs. "Read and change all your data on all websites" is technically possible and commercially fatal. A professional extension asks for the minimum access at the moment the user understands why.

Know the three common access shapes

{
  "permissions": ["activeTab", "scripting", "storage"],
  "optional_host_permissions": ["https://*/*", "http://*/*"]
}

activeTab grants temporary access to the current tab after a meaningful user gesture such as clicking the toolbar action. Broad host access means persistent visibility across matching sites. optional_host_permissions are not granted at install time; the extension asks later with chrome.permissions.request.

const granted = await chrome.permissions.request({
  origins: ["https://mail.example/*"]
});
if (!granted) {
  showEnableInSettingsState();
  return;
}
await chrome.scripting.executeScript({
  target: { tabId },
  files: ["mail-audit.js"]
});

The pattern matters: request access in response to a click, explain the feature first, and handle denial as a normal state. A user who declines is not an error path.

Permissions are additive in the user's mind

Users do not parse the distinction between tabs and activeTab carefully, but the browser does. The tabs permission exposes sensitive tab metadata such as URL and title across the browser; do not request it merely because you need a tab ID. Tab IDs are available from events and action clicks without it.

Host permissions deserve equal care. https://*/* covers most of the web but excludes http: pages; <all_urls> includes more schemes and is the broadest request. Write the narrowest match that includes the real feature. If your product works on three customer domains, enumerate them.

Make removal part of the design

Enterprise users and careful reviewers look for reversible consent. Use chrome.permissions.contains before showing feature state, and chrome.permissions.remove when a user disconnects a site:

await chrome.permissions.remove({ origins: ["https://mail.example/*"] });

Then make the UI honest. A disconnected site should stop being scanned even if old data remains in storage; access revocation is behavior, not just a checkbox.

Field notes

  • Never request clipboardRead or clipboardWrite because copying feels convenient; use user-triggered navigator.clipboard where possible.
  • Some API permissions imply visible warnings while others are silent; test the install prompt in a clean profile.
  • Optional permissions must still be declared in the manifest before they can be requested.
  • Feature-detect with chrome.permissions.contains; browsers differ in edge cases and enterprises can force-install policies.

Was this lesson helpful?

Sign in to rate