Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8547163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:12:25+00:00 2026-06-11T13:12:25+00:00

Can I allow the domain matching for my extension to be user configurable? I’d

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:12:27+00:00Added an answer on June 11, 2026 at 1:12 pm

    To implement customizable “match patterns” for content scripts, the Content script need to be executed in by the background page using the chrome.tabs.executeScript method (after detecting a page load using the chrome.tabs.onUpdated event 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:

    /**
      * @param String input  A match pattern
      * @returns  null if input is invalid
      * @returns  String to be passed to the RegExp constructor */
    function parse_match_pattern(input) {
        if (typeof input !== 'string') return null;
        var match_pattern = '(?:^'
          , regEscape = function(s) {return s.replace(/[[^$.|?*+(){}\\]/g, '\\$&');}
          , result = /^(\*|https?|file|ftp|chrome-extension):\/\//.exec(input);
    
        // Parse scheme
        if (!result) return null;
        input = input.substr(result[0].length);
        match_pattern += result[1] === '*' ? 'https?://' : result[1] + '://';
    
        // Parse host if scheme is not `file`
        if (result[1] !== 'file') {
            if (!(result = /^(?:\*|(\*\.)?([^\/*]+))(?=\/)/.exec(input))) return null;
            input = input.substr(result[0].length);
            if (result[0] === '*') {    // host is '*'
                match_pattern += '[^/]+';
            } else {
                if (result[1]) {         // Subdomain wildcard exists
                    match_pattern += '(?:[^/]+\\.)?';
                }
                // Append host (escape special regex characters)
                match_pattern += regEscape(result[2]);
            }
        }
        // Add remainder (path)
        match_pattern += input.split('*').map(regEscape).join('.*');
        match_pattern += '$)';
        return match_pattern;
    }
    

    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 localStorage or chrome.storage.

    // Example: Parse a list of match patterns:
    var patterns = ['*://*/*', '*exampleofinvalid*', 'file://*'];
    
    // Parse list and filter(exclude) invalid match patterns
    var parsed = patterns.map(parse_match_pattern)
                         .filter(function(pattern){return pattern !== null});
    // Create pattern for validation:
    var pattern = new RegExp(parsed.join('|'));
    
    // Example of filtering:
    chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
        if (changeInfo.status === 'complete') {
            var url = tab.url.split('#')[0]; // Exclude URL fragments
            if (pattern.test(url)) {
                chrome.tabs.executeScript(tabId, {
                    file: 'contentscript.js'
                    // or: code: '<JavaScript code here>'
                    // Other valid options: allFrames, runAt
                });
            }
        }
    });
    

    To get this to work, you need to request the following permissions in the manifest file:

    • "tabs" – To enable the necessary tabs API.
    • "<all_urls>" – To be able to use chrome.tabs.executeScript to 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 of chrome.permissions).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I allow users to enter both subdomain and domain names without the
How can I allow users to log into one domain and automatically be logged
How can I annotate my model so I can allow only alphabets like A-Z
What are the required steps to properly allow domain users access to reports via
So, how does it work? How come having a receiver.html can allow cross domain
How can allow Facebook access to my test domain for Facebook connecting while at
I want an opt-in beta site, that users can also opt-out of, On domain.com
Flash cross-domain policy files only allow you to specify allow-domain-from tags. I'd like to
How can I forward short-dom.com to long-domain.com ? I keep seeing examples like: RewriteCond
I have a site that can allow me to access the mobile version of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.