Can I allow the domain matching for my extension to be user configurable?
I’d like to let my users choose when the extension runs.
Can I allow the domain matching for my extension to be user configurable? I’d
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To implement customizable “match patterns” for content scripts, the Content script need to be executed in by the background page using the
chrome.tabs.executeScriptmethod (after detecting a page load using thechrome.tabs.onUpdatedevent listener).Because the match pattern check is not exposed in any API, you have to create the method yourself. It is implemented in
url_pattern.cc, and the specification is available at match patterns.Here’s an example of a parser:
Example: Run content script on pages which match the pattern
In the example below, the array is hard-coded. In practice, you would store the match patterns in an array using
localStorageorchrome.storage.To get this to work, you need to request the following permissions in the manifest file:
"tabs"– To enable the necessarytabsAPI."<all_urls>"– To be able to usechrome.tabs.executeScriptto execute a content script in a specific page.A fixed list of permissions
If the set of match patterns is fixed (ie. the user cannot define new ones, only toggle patterns),
"<all_urls>"can be replaced with this set of permissions. You may even use optional permissions to reduce the initial number of requested permissions (clearly explained in the documentation ofchrome.permissions).