Menu

Ask for one site at a time: optional host permissions and dynamic content scripts in MV3
📰

Ask for one site at a time: optional host permissions and dynamic content scripts in MV3

DEV Community: javascript·Emir Mrkaljević·about 3 hours ago
#LGbA9t7e
#devtojavascript#devto#dev#script#chrome
Reading 0:00
15s threshold

ShrinkWatch EU is an open source extension that shows the price per kg or litre on 71 European supermarket web shops. Asking for all of them at install time would mean more than 180 site patterns in the permission warning, and a harder store review. So only six shops are enabled at install. Every other shop is switched on by the user, one at a time, from the popup.

This post is how that works in Manifest V3, and the three bugs I hit on the way.

The manifest

The six default shops go in host_permissions and a static content_scripts entry. Everything else goes in optional_host_permissions :

{ "permissions" : [ "storage" , "scripting" , "activeTab" ], "host_permissions" : [ "https://*.konzum.hr/*" ], "optional_host_permissions" : [ "https://*.rewe.de/*" , "https://*.lidl.fr/*" ] }

Enter fullscreen mode

Exit fullscreen mode

activeTab covers a "Check this page now" button that works on any site, once, without a standing permission.

Asking for the permission

The request must run directly in the click…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.