w3c / webextensions

Charter and administrivia for the WebExtensions Community Group (WECG)
Other
575 stars 50 forks source link

Proposal: add commands.OnCommandData similar to menus.OnClickData #568

Open jpc-ae opened 3 months ago

jpc-ae commented 3 months ago

A sticking point with adding shortcut keys at the moment is the lack of information provided to the extension when onCommand is called.

My use case involves storing selected text or inputting data into a field when the user requests it. In order to limit the permissions required, my app only requests the activeTab permission with <all_urls> specified under optional_host_permissions. When a user clicks an item in the contextmenu, my service worker is provided with an OnClickData object I can use to handle embedded frames by:

  1. Confirming the extension has required host permissions for the frameUrl and otherwise request it of the user
  2. Confirming the frameId required to inject the script

Without this information and no reliable way of getting a frameId from the parent page, extensions are required to:

  1. Have the webNavigation permission to determine what frames are on the page (since the frame src is not a reliable indicator of its current url)
  2. Potentially request more host permissions than necessary when a page has several frames embedded, just to spy out which one currently has focus

At least for my use case, commands including a data object similar to the one for menus would mean less need for additional permissions and workarounds, as well as less friction for users. I imagine there will be use cases for many of the other fields exposed in OnClickData as well.

oliverdunk commented 2 months ago

For Chrome, switching to our follow-up label as I need to get thoughts from the team on this.