• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

code-mancers/interceptor: A browser extension to mock AJAX requests at the brows ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

code-mancers/interceptor

开源软件地址:

https://github.com/code-mancers/interceptor

开源编程语言:

TypeScript 46.8%

开源软件介绍:

Interceptor

Build Status GitHub Commitizen friendly

A browser extension that mocks AJAX request at the browser level so you can run front ends without really starting a backend server.

Firefox : Mozilla Add-on

Chrome : Chrome Web Store

Development

In Chrome

$ yarn install
$ yarn run watch
# Install "./dist" directory as "unpacked chrome extension" (google it!)

In Firefox

$ yarn install
$ yarn run watch
$ yarn global add web-ext 
$ web-ext run -s dist -f "/usr/bin/firefox"

Release

$ yarn run build
$ AMO_API_KEY=<amo api key> AMO_API_SECRET=<amo api secret> NEW_VERSION=0.3.2 yarn run release

How to use

Listening to requests made by the browser

Once you open the extension popup, it shows a UI as seen below. By default, Intercept Mode is ON.

Interceptor extension default popup

Once you start listening, it shows the count of total AJAX requests in a small badge and list of incoming XHR requests in the popup like this:

Interceptor extension popup showing a list of AJAX requests

Request headers for listened requests are listed below the response form as shown in the screenshot.

A screenshot of Listened requests with request headers

Response data returned by backend server

Many a times, before defining you mock response text, you would want to look at the response data returned by the server when the request is made. On clicking Fetch Response button, the textarea gets filled with the response data from the real server as shown below. However, You can completely skip this step and move on to typing out mock response text.

Fetching data from backend server

Specifying mock response data

You can click the small arrow beside the URL, which shows a form in which you can specify a response to mock, when the same request is encountered next. You also need to specify the Content-Type header field and status code for the mock response through the dropdown available as shown below.

Specify mock responses using Interceptor as shown

Once the above fields are filled and checkbox is checked, click the INTERCEPT button. If the interception is successfull, it shows a success message as below:

Success message shown by Interceptor upon sucessful interception

You can intercept/mock multiple calls by checking as many checkboxes as you want

Success message shown by Interceptor upon sucessful interception

Henceforth the same AJAX request is made by the browser, the browser is given a fake/mock response instead of the real one.

You can also stop listening for AJAX calls by clicking the STOP LISTENING button. Requests made henceforth won't be listed on UI.

The toggle switch is used to disable INTERCEPTOR. If the toggle is switched to OFF state, it displays a message saying Interception Disabled as below.

Message shown by Interceptor on disabling

In the disabled state, the extension won't mock any previously intercepted calls. Instead all XHR's are routed to the server. The extension's icon beside the url address bar turns red for that particular tab as in screenshot above.

To mock the calls again, just toggle the switch to ON state, check the requests that are to be mocked and click INTERCEPT button.

This blogpost makes things much more clear.

TODO

  • A user should be able to click on the extension button and see a popup with a list of all AJAX requests.
  • A user should be able to "watch" ajax requests using a URL pattern.
  • If watched requests are in pre-flight, block everything and ask the user how to handle it.
  • The user may choose to let the request pass through or fill in mock response using a form.
  • Persist settings for each URL in localStorage.
  • Mocked requests should hit a sinon fakeServer.
  • User should be able to disable/enable mocking for a page without clearing persisted settings for the URL.

Attribution

Icons for this projects are used from Font Awesome

License

MIT




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
icpantsparti/firefox-user.js-tool: Interactive view, compare, and more for Firef ...发布时间:2022-06-08
下一篇:
OneKeyHQ/app-monorepo: 发布时间:2022-06-08
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap