Skip to content

An extension plugin for Chrome that modifies the response of AJAX requests. 一个修改Ajax请求响应结果的Chrome扩展插件

License

Notifications You must be signed in to change notification settings

senyawang/ajax-tools

 
 

Repository files navigation

English | 简体中文


An extension plugin for Chrome that modifies the response of AJAX requests.

Main features:

  • Intercept and modify the response of XMLHttpRequest and fetch requests, including 404 status requests.
  • Match requests based on regular expressions and HTTP request methods.
  • Edit response results in JSON or JavaScript format, with support for mock.js syntax.
  • Easily create mock scenarios in JavaScript programming by accessing original request information from the arguments parameter.
  • New U-Network panel in DevTools for quickly intercepting requests and modifying response results [added in version 0.0.4].
  • Support change the request URL, body and request headers [added in version 0.0.5].

Install

https://chrome.google.com/webstore/detail/ajax-interceptor-tools/kphegobalneikdjnboeiheiklpbbhncm

Usage

Video: https://www.youtube.com/watch?v=HPtQO0Fyb7I

Edit response results using JavaScript

When editing the response results using JavaScript, a function is generated and executed via new Function(responseText), and the returned result is the return value of the function.

Example:

const data = [];
for (let i = 0; i < 10; i++) {
  data.push({ id: i });
}
return {
  data
}

Support for Mock.js syntax
Example:

const data = Mock.mock({
    // The value of the property "list" is an array that contains 1 to 10 elements.
    'list|1-10': [{
        // The property "id" is an auto-incremented number starting from 1 and increasing by 1 each time.
        'id|+1': 1
    }]
});
return {
  data
}

Retrieve original request information through the arguments parameter and easily create mock scenarios using simple programming

Example:

let { method, payload, originalResponse } = arguments[0];
if (method === 'get') { // Method
  // do something
}
if (payload) { // parameters { queryStringParameters,requestPayload }
  // do something
}
return originalResponse;

License

MIT License.

About

An extension plugin for Chrome that modifies the response of AJAX requests. 一个修改Ajax请求响应结果的Chrome扩展插件

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 82.0%
  • TypeScript 16.6%
  • CSS 1.2%
  • HTML 0.2%