• Stars
    star
    199
  • Rank 196,073 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A browser extension to mock AJAX requests at the browser level

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

More Repositories

1

invoker

An awesome utility to manage all your processes in development environment
Ruby
460
star
2

rbkit

A new profiler for Ruby. With a GUI
Ruby
357
star
3

rapidfire

Making dynamic surveys should be easy!
Ruby
308
star
4

restful_route_version

A Rails plugin to allow versioning of restful routes
Ruby
42
star
5

rbkit-client

Rbkit Desktop application
C++
32
star
6

rapidfire-app

Rails app for managing surveys
Ruby
16
star
7

ministry_of_state

Modern ActiveRecord state machine plugin
Ruby
15
star
8

borg

A distributed Test Suite runner for Rails, using Eventmachine and Redis
Ruby
15
star
9

toothpick

For the fine art of picking
Ruby
12
star
10

rails_legit

Provides a DSL for common validation use-cases like Date, Array, DateTime etc.
Ruby
12
star
11

rspec-simple

A simple rspec mode for emacs
Emacs Lisp
11
star
12

picks

Daily collection of Codemancers picks
6
star
13

rails-mailgun

Rails integration for Mailgun service
Ruby
6
star
14

rpbundle

Use Gemfiles in your ruby-processing sketches
Ruby
6
star
15

reddit-web

An alternative interface to Reddit.
JavaScript
5
star
16

bitbucket.ex

Elixir lib for Bitbucket v2.0 APIs
Elixir
4
star
17

hubot-pr-fu

Commands for working with open Github PRs for a repo
CoffeeScript
4
star
18

sicp

another attempt at sicp book
Clojure
3
star
19

phoenix-distillery-blogpost-example

JavaScript
3
star
20

invoker-app

A systemtray/menubar app to easily manage invoker
JavaScript
3
star
21

strapi-plugin-stellate

Strapi Plugin Stellate is a plugin for the Strapi headless CMS that provides a convenient way to purge the cache.
JavaScript
3
star
22

rbkit-electron-redux

Electron Client that connects to Rbkit
JavaScript
2
star
23

hctbox-demo

Demo app for hctbox gem
Ruby
2
star
24

littil.ext

Littil's browser extensions for firefox and chrome browsers
JavaScript
2
star
25

hctbox

HTML CSS Toolbox: still WIP, not even alpha!
Ruby
2
star
26

rubyconfindia_talk_extensions

C Extension code used for the talk
C
2
star
27

json_schema_sample_app

A sample Sinatra app demonstrating the usage of JSON Schema specification
Ruby
2
star
28

wufoo-assets

CSS
1
star
29

diffity.rb

ruby gem to integrate with integration-diff
Ruby
1
star
30

nudge

Nudge ยท Without bells and whistles
Elixir
1
star
31

elixir-exit-handling

Elixir
1
star
32

gitlab-dependabot-example

Rails app that simply shows your Gitlab Repositories and later on adds dependabot service to them
Ruby
1
star
33

rbkit-chartjs

experimenting with rbkit-chartjs
JavaScript
1
star
34

blogstyles

CSS
1
star
35

webpack-cheatsheet

A repository for webpack config/documentation and to track and help issues with our webpack setup or frontend setup in general.
JavaScript
1
star
36

invoker.el

An Emacs package for managing invoker
Emacs Lisp
1
star
37

rbkit-chrome

Rbkit Client in the form of a Google Chrome extension
JavaScript
1
star
38

exray

A tool to visualize Erlang/Elixir process related events
Elixir
1
star
39

frisk

Because nobody trusts APIs before you frisk them
Ruby
1
star
40

pr_wooster

A Jenkins plugin that displays pull request status on github
Java
1
star
41

android-notification-receiver

Receives SMS notification (only SMS for now) and displays in a list.
Java
1
star
42

rbkit-atom

Clone of rbkit-client that uses atom-shell
JavaScript
1
star