Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test optional permissions in a Chrome extension?

I'm thinking of moving some of the permissions in an unpublished Chrome extension to being optional instead of required in the manifest, and wanted to test the user flow.

Calling chrome.permissions.request() in an unpacked extension seems to just succeed silently. The browser dialog that the user should see isn't displayed.

This Chrome developer page suggests you can test the normal user flow using a packaged .crx file:

If you'd like to see exactly which warnings your users will get, package your extension into a .crx file, and install it.

However, Chrome no longer seems to let you install an arbitrary .crx file outside of the Chrome Webstore. Dragging and dropping the file on the Extensions page lists it, but the Enabled checkbox is disabled. This SO comment indicates that testing permissions in this way is likely no longer possible, but I haven't seen any official documentation about it.

I was actually able to install and enable a non-Webstore .crx file by adding it to the extension whitelist in the Windows registry, using these instructions, but that extension didn't trigger the permission request dialogs either.

So my questions are:

  1. Is there a way to test the permission request flow other than publishing an extension to the Chrome Webstore?
  2. What's the best way to remove the optional permissions once you've accepted them, in order to test the flow again? Delete the extension? Call chrome.permissions.remove()?
like image 219
jdunning Avatar asked Mar 04 '18 01:03

jdunning


People also ask

How do I check permissions on my extensions?

To view the permissions of any installed extension, unpacked or from the store, open chrome://extensions page and click the details button on that extension's card. The circled part is for API permissions.

How do I manage Chrome extension permissions?

Click the “Details” button for the extension you want to control. To the right of “Allow this extension to read and change all data on the websites you visit,” choose “On specific sites.” You can now control the specific list of sites the extension can access from the “Allowed sites” list.


1 Answers

Turns out I confused myself by requesting the "sessions" permission when the extension already had a required "tabs" permission. Apparently, requesting "sessions" when you already have "tabs" doesn't trigger the permissions dialog.

However, calling something like chrome.permissions.request({ permissions: ["bookmarks"] }) does, in fact, show the permissions dialog, even in an unpacked extension.

So the answers are:

  1. There's no need to publish an extension to the Chrome Webstore. Just request an optional permission with your local unpacked extension to see the dialog.

  2. It looks like the only way to trigger the permissions dialog again is to delete the extension completely and reinstall it. Calling chrome.permissions.remove() does remove it as far as the APIs go, but the permission is silently re-added if it's requested again.

like image 102
jdunning Avatar answered Oct 13 '22 02:10

jdunning