Prevent access to URLs that do not match a certain pattern in Chrome

I will be implementing a filter to block request URLs that do not match a specific pattern.

To achieve this, you can utilize the request blocking feature within Google Chrome's network tab. Simply right click on the request Row and select "block request URL".

For instance, in the request blocking tab, I have 7 XMLHttpRequest(XHR) URLs sent with Ajax:

You can add a pattern (e.g., *family*) and block requests with that specific pattern by clicking the plus sign.

Remember: Patterns are case sensitive.

Looking to block requests without the word "family"? Here's how:

Is it possible to use regular expressions for this purpose?

Answer №1

To prevent requests from the client browser, you can utilize HTTP Request Blocker and Request blocker extension available for Google Chrome.

When it comes to managing requests on the client-side, consider implementing the following code snippet to create an interceptor in AngularJS that allows you to control requests before and after they are sent:

myApp.config(['$httpProvider', '$locationProvider',
            function ($httpProvider, $locationProvider) {
            $httpProvider.interceptors.push(function ($q) {
                return {
                    'request': function (config) {

                    },
                    'response': function (config) {

                    },
                    'requestError': function (config) {

                    },
                    'responseError': function (config) {

                    },
                }
            });
        }]);

Request blocker extension

Interceptors guide

Answer №2

If you take a closer look at the DevTools source code

https://github.com/ChromeDevTools/devtools-frontend/blob/aaad45c61dfb22ad885b507a0f38f19863c09553/front_end/network/BlockedURLsPane.js#L194

    for (var blockedUrl of this._blockedCountForUrl.keys()) {
      if (this._matches(url, blockedUrl))
        result += this._blockedCountForUrl.get(blockedUrl);
    }
    return result;
  }

  /**
   * @param {string} pattern
   * @param {string} url
   * @return {boolean}
   */
  _matches(pattern, url) {
    var pos = 0;
    var parts = pattern.split('*');
    for (var index = 0; index < parts.length; index++) {
      var part = parts[index];
      if (!part.length)
        continue;
      pos = url.indexOf(part, pos);
      if (pos === -1)
        return false;
      pos += part.length;
    }
    return true;
  }

The interesting thing is that it doesn't utilize RegEx. Therefore, in simple terms, it does not have support for using regular expressions. However, the good news is that you can easily implement this feature yourself by adding regex patterns and submitting a pull request to suggest this enhancement.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Executing Ajax requests to interact with a RESTful API

After developing a back end REST API using Slim Framework and closely following the REST format, I ran into an issue when working on the Front End. It seems that AJAX functions well with parameters but not paths. I am considering outsourcing or creating a ...

Dealing with AngularJS memory leaks caused by jQuery

How can I showcase a custom HTML on an AngularJS page using the given service? app.service('automaticFunctions', function ($timeout) { this.init = function initAutomaticFunctions(scope, $elem, attrs) { switch (scope.content.type) { ...

Can Ajax and WAMP Server work together?

After spending a considerable amount of time going back and forth on Google, I couldn't figure out why my AJAX was not refreshing the content beyond its initial load. Frustrated, I decided to give up and write a lengthy post here seeking help. However ...

The success callback method is no longer correctly referencing the variable due to a change in the AJAX request

Imagine you have a table in your HTML file with the following rows, where {{ }} represent variables: <tr id="{{ object.id }}"> <td class="name">{{ object.name }}</td> </tr> <tr id="{{ object.id }}"> <td class="nam ...

At what point are routed components initialized?

Here is a route setup I am working with: path: ':id', component: ViewBookPageComponent }, After adding this route, an error keeps popping up: Error: Cannot read property 'id' of null I haven't included a null check in the compo ...

Trying to assign a property to an undefined variable inside a function

At the moment, I am configuring error messages on a login page for an extension using vue, and encountering issues within the importCreds() function. data(){ return { url:'', apikey:'', error:'', } }, meth ...

The ng-model is not properly syncing values bidirectionally within a modal window

I am dealing with some html <body ng-controller="AppCtrl"> <ion-side-menus> <ion-side-menu-content> <ion-nav-bar class="nav-title-slide-ios7 bar-positive"> <ion-nav-back-button class="button-icon ion-arrow-le ...

Is there a way to add pins to separate entity layers, and then remove them from a specific entity layer using Bing Maps AJAX Control, Version 7.0?

Currently, I am utilizing Bing Maps to display store locations on a map. The information about the stores is coming from a dynamic JSON response. When the page loads, the map shows local stores with pushpins and infoboxes. As the map pans, my goal is to re ...

Error message: "Element not found in Selenium WebDriver on (bamboo)"

Just diving into the world of Selenium testing with Chrome webdriver! The element I need to click on is <a href="/myclassroom/studentsclass" class="current">Students</a> I wrote a simple code snippet to perform this click action: driver.fi ...

Identifying and Blocking Users from Accessing External Domains Outside of the Angular Application

I am working on an angular application and I need to implement a feature where I can detect when a user navigates outside of the app domain from a specific component. For instance, let's say the user is on the upload component processing important in ...

Error message: JQuery IAS Infinite Scrolling + Packery - The IASCallbacks function is not declared

I'm having difficulty integrating Packery with Jquery Infinite AJAX scroll on a Tumblr theme. I keep getting the error "Uncaught ReferenceError: IASCallbacks is not defined" and I can't figure out why. Here's the code I've put together ...

Guide for utilizing ajax and php to establish a connection with a mysql database when developing with phonegap

I am currently developing a phonegap application and I'm facing an issue with displaying content from MySQL. Since I can't use PHP pages in phonegap, I decided to utilize web services in HTML for connecting to MySQL. However, my Ajax web service ...

Is Q.js capable of functioning independently from node.js and require()?

Currently experimenting with the latest version of q.js to integrate promises into my ajax calls without utilizing node.js at all. I retrieved the most recent version from https://github.com/kriskowal/q and only included q.js in my project. While testing, ...

What is the best approach to establish multiple global prefixes in a NestJS project?

I am looking to define multiple Global Prefixes for my application such as: admin/products admin/users admin/... api/products api/search api/... shop/products shop/cart shop/... In the main.ts file, I can set a single global prefix using th ...

Displaying content based on changing conditions fetched from the database

We are currently developing a dynamic form system where users can create custom questions in the admin panel and set conditions to display them based on the values of other questions. ng-show="((UserCode==10003 && Name=='Ankur') ||(State ...

Personalized Svelte interface Slider tag

I am trying to customize the label of a smui/slider in a tick marks and discrete slider. While I found instructions on how to do this using material web components at https://github.com/material-components/material-components-web/tree/v13.0.0/packages/mdc- ...

Determine image size (pre-upload)

One of the requirements for a project I am working on is to verify the dimensions (width and height) of images before uploading them. I have outlined 3 key checkpoints: 1. If the dimensions are less than 600 X 600 pixels, the upload should be rejected. ...

Create a function called "insertEvent" that will insert a new event on a specified date

Below is the data structure for storing affairs according to years, months, and days: let affairs = { 2018: { 11: { 29: ['task111', 'task112', 'task113'], 30: ['task121', 'ta ...

Error: Unable to execute $(...).stellar since it is not a recognized function

Having some trouble implementing the stellar plugin. I've included all the necessary js, but keep getting an error in the dev tools console: 'Uncaught TypeError: $(...).stellar is not a function'. Here's what I have in the head tags: ...

Using a jQuery calendar to generate a JSON date range

In my current situation, I am faced with a task where I need to choose a date from a jQuery Calendar and then, using ajax, cycle through a JSON file. The problem I encounter stems from dealing with date ranges, such as startdate and enddate: { "campu ...