Apis for ajax state events


Is there any apis for global request/response events?
Similar to Jquery.ajaxComplete?


May I suggest using a node html request instead of Ajax? The module request is awesome and can do anything you’d want.


Sorry, I should explain my question.
I want to get ALL ajax response data for ALL ajax request in a site.

So i don’t think the request module is what i want.


@mark_hahn is right, if you need to query things on a distant server, the request module is the best option, simple, fast, and based on node API (streams & events).

A bit more details about what you try to achieve would help us understand your problem so that we can help you.


I am not agree with this view.

I want to get ALL response data for ALL ajax request on a running site, which uses angularjs as ui framework.

If use request module, I should code for EVERY request and it will be inefficient.

So here is what i want:
The apis for request/response event in a opened window. just similar to Jquery.ajaxComplete.

Doc for Jquery.ajaxComplete: http://api.jquery.com/ajaxComplete/


You can write your own wrapper for the request module. Something like

# myRequest.coffee
request = require 'request'

module.exports = myRequest = (url, callback) ->
  request url, (err, res, body) ->
    # do your stuff here
    # finally call the callback
    callback err, res, body

or in plain JS

// myRequest.js
var request = require('request');
var myRequest;

module.exports = myRequest = function(url, callback) {
  request(url, function(err, res, body) {
    // do your stuff here
    // finally call the callback
    callback(err, res, body);


Wait, if your app uses AngularJS today, then why not use the same mechanism that any other Angular web app uses? Or even jQuery AjaxComplete? The HTML pages in Atom Shell apps behave pretty much like HTML pages in web apps in this regard, I believe.


Thanks.But the problem is not a single request/response, It’s EVERY request/response.
So I think we should get out of the request/response code or something, and think about GLOBAL EVENTS or atom-shell apis.


How can i get all ajax request/response in angularjs?

The Jquery.ajaxComplete has a note here:

If .ajax() or .ajaxSetup() is called with the global option set to false, the .ajaxComplete() method will not fire.

unfortunately, the global option is setted to false…


If you make every request with the myRequest function from my example, i.e. require('myRequest')(url, callback), your own piece of code would run on every request. Or maybe I just don’t understand what it is you want.


I can’t make every request with myRequest because the site is running and it’s using angularjs.

And my goal is:

  1. open the site in atom-shell.
  2. get EVERY ajax request/response data in this site.

Are we clear?


@oonxt The people commenting on this topic are the experts in getting Atom to do all kinds of things. These people are trying to help you. If they aren’t helping you the way you’d like, perhaps you should consider that there is a reason for that?

And no, “Get every AJAX request/response data in this site” is not clear, at least not to me. Do you want the code to magically figure out what all possible AJAX requests one could make to site www.example.com, make them and display the responses? If so, that’s a pretty tall order because a lot of times AJAX requests require parameters …

For example, let’s take the GitHub Issue Search API. If I just call http://api.github.com/search/issues with no query text, I get back a response … but it’s an error. Whereas if I call http://api.github.com/search/issues?q=user:atom%20keybinding, I get something useful:

  "total_count": 335,
  "incomplete_results": false,
  "items": [
      "url": "https://api.github.com/repos/atom/settings-view/issues/363",
      "labels_url": "https://api.github.com/repos/atom/settings-view/issues/363/labels{/name}",
      "comments_url": "https://api.github.com/repos/atom/settings-view/issues/363/comments",
      "events_url": "https://api.github.com/repos/atom/settings-view/issues/363/events",
      "html_url": "https://github.com/atom/settings-view/issues/363",
      "id": 56060217,
      "number": 363,
      "title": "Copying keybinding with Ctrl+\\ yields invalid CSON for keymap file",
      "user": {
        "login": "D-side",
        "id": 2567124,
        "avatar_url": "https://avatars.githubusercontent.com/u/2567124?v=3",
        "gravatar_id": "",
        "url": "https://api.github.com/users/D-side",
        "html_url": "https://github.com/D-side",
        "followers_url": "https://api.github.com/users/D-side/followers",
        "following_url": "https://api.github.com/users/D-side/following{/other_user}",
        "gists_url": "https://api.github.com/users/D-side/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/D-side/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/D-side/subscriptions",
        "organizations_url": "https://api.github.com/users/D-side/orgs",
        "repos_url": "https://api.github.com/users/D-side/repos",
        "events_url": "https://api.github.com/users/D-side/events{/privacy}",
        "received_events_url": "https://api.github.com/users/D-side/received_events",
        "type": "User",
        "site_admin": false
      "labels": [
          "url": "https://api.github.com/repos/atom/settings-view/labels/bug",
          "name": "bug",
          "color": "fc2929"
      "state": "open",
      "locked": false,
      "assignee": null,
      "milestone": null,
      "comments": 0,
      "created_at": "2015-01-30T17:19:57Z",
      "updated_at": "2015-01-30T18:45:23Z",
      "closed_at": null,
      "body": "While overriding a tree view toggle (`Ctrl+\\`) I copied the keybinding to clipboard.\r\n\r\n![Screenshot of the copy button](http://i.imgur.com/jBoZZSr.png)\r\n\r\nThis is what I got:\r\n\r\n    '.platform-win32, .platform-linux':\r\n       'ctrl-\\': 'tree-view:toggle'\r\n\r\nBackslash is an escape character, so the closing single quote gets escaped and the CSON turns out to be invalid. Should be:\r\n\r\n    '.platform-win32, .platform-linux':\r\n      'ctrl-\\\\': 'tree-view:toggle'",
      "score": 13.635743
      "url": "https://api.github.com/repos/atom/settings-view/issues/163",
      "labels_url": "https://api.github.com/repos/atom/settings-view/issues/163/labels{/name}",
      "comments_url": "https://api.github.com/repos/atom/settings-view/issues/163/comments",
      "events_url": "https://api.github.com/repos/atom/settings-view/issues/163/events",
      "html_url": "https://github.com/atom/settings-view/issues/163",
      "id": 40934513,
      "number": 163,
      "title": "Feature request for easier keybinding setup",
      "user": {
        "login": "ilanbiala",
        "id": 3695164,
        "avatar_url": "https://avatars.githubusercontent.com/u/3695164?v=3",
        "gravatar_id": "",
        "url": "https://api.github.com/users/ilanbiala",
        "html_url": "https://github.com/ilanbiala",
        "followers_url": "https://api.github.com/users/ilanbiala/followers",
        "following_url": "https://api.github.com/users/ilanbiala/following{/other_user}",
        "gists_url": "https://api.github.com/users/ilanbiala/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/ilanbiala/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/ilanbiala/subscriptions",
        "organizations_url": "https://api.github.com/users/ilanbiala/orgs",
        "repos_url": "https://api.github.com/users/ilanbiala/repos",
        "events_url": "https://api.github.com/users/ilanbiala/events{/privacy}",
        "received_events_url": "https://api.github.com/users/ilanbiala/received_events",
        "type": "User",
        "site_admin": false
      "labels": [
          "url": "https://api.github.com/repos/atom/settings-view/labels/enhancement",
          "name": "enhancement",
          "color": "84b6eb"
      "state": "open",
      "locked": false,
      "assignee": null,
      "milestone": null,
      "comments": 10,
      "created_at": "2014-08-22T18:07:10Z",
      "updated_at": "2014-11-16T03:11:53Z",
      "closed_at": null,
      "body": "I'm currently experimenting with Atom keymaps, and I noticed that creating a keybinding seems somewhat complicated. I'd like to suggest a feature to make it simpler for most keymaps people will want to change. Take this list of bindings for example:\r\n\r\n![screenshot 2014-08-18 17 24 35](https://cloud.githubusercontent.com/assets/3695164/3958260/52451eb0-271e-11e4-9c27-3c17e7a06707.png)\r\n\r\nIf I'd like to change the keystroke for the first command (`autocomplete-plus:confirm`), I can just click on the `<li>`, and it will record my keystroke and override the package's default by inserting it into a keymap.cson. Something like this \r\n![screenshot 2014-08-18 17 28 17](https://cloud.githubusercontent.com/assets/3695164/3958308/b295f4ce-271e-11e4-8960-9a7e2c48a1a7.png)\r\nwould show up and I could record my new keybinding.\r\n\r\nIt's just a thought, but I think that if it were implemented, many people would appreciate it and use it most of the time when altering keymaps in Atom.",
      "score": 11.118727
      "url": "https://api.github.com/repos/atom/whitespace/issues/11",
      "labels_url": "https://api.github.com/repos/atom/whitespace/issues/11/labels{/name}",
      "comments_url": "https://api.github.com/repos/atom/whitespace/issues/11/comments",
      "events_url": "https://api.github.com/repos/atom/whitespace/issues/11/events",
      "html_url": "https://github.com/atom/whitespace/issues/11",
      "id": 28432779,
      "number": 11,
      "title": "Save without stripping command/keybinding?",
      "user": {
        "login": "ho0ber",
        "id": 431445,
        "avatar_url": "https://avatars.githubusercontent.com/u/431445?v=3",
        "gravatar_id": "",
        "url": "https://api.github.com/users/ho0ber",
        "html_url": "https://github.com/ho0ber",
        "followers_url": "https://api.github.com/users/ho0ber/followers",
        "following_url": "https://api.github.com/users/ho0ber/following{/other_user}",
        "gists_url": "https://api.github.com/users/ho0ber/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/ho0ber/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/ho0ber/subscriptions",
        "organizations_url": "https://api.github.com/users/ho0ber/orgs",
        "repos_url": "https://api.github.com/users/ho0ber/repos",
        "events_url": "https://api.github.com/users/ho0ber/events{/privacy}",
        "received_events_url": "https://api.github.com/users/ho0ber/received_events",
        "type": "User",
        "site_admin": false
      "labels": [
          "url": "https://api.github.com/repos/atom/whitespace/labels/enhancement",
          "name": "enhancement",
          "color": "84b6eb"
      "state": "open",
      "locked": false,
      "assignee": null,
      "milestone": null,
      "comments": 2,
      "created_at": "2014-02-27T16:29:57Z",
      "updated_at": "2014-07-08T12:31:24Z",
      "closed_at": null,
      "body": "Perhaps it might be nice to add a command/keybinding to allow one to save a file without stripping trailing whitespace and adding a trailing newline, rather than requiring the user to disable the package, go back to the buffer in question, save, and reenable the package.\r\n\r\nMost of the time I want the behavior this package offers, but every now and then I want to be able to save a file without.\r\n\r\nFor instance, if I start to make changes in multiple files and I ultimately decide to revert a change in one of those files and intend to leave it untouched, but because saving the file will clean it up, I'll either need to checkout that file to revert, leave some unstaged changes hanging around, or commit cleanup changes to a file that doesn't need to be in that commit. With my proposed change, it would be as easy as \"Undo, nostrip-save\" (after making sure the file is no longer highlighted in the tree view as having changes).\r\n\r\nAnother example is when working in a codebase I don't control: I may want to make a single line change so I can submit a pull request without also including dozens of whitespace cleanups (which might create merge conflicts by the time the maintainer gets around to looking at my change), but without first disabling this package, I can't save that one-line change in someone else's messy codebase.",
      "score": 11.044334
      "url": "https://api.github.com/repos/atom/settings-view/issues/165",
      "labels_url": "https://api.github.com/repos/atom/settings-view/issues/165/labels{/name}",
      "comments_url": "https://api.github.com/repos/atom/settings-view/issues/165/comments",
      "events_url": "https://api.github.com/repos/atom/settings-view/issues/165/events",
      "html_url": "https://github.com/atom/settings-view/issues/165",
      "id": 41199446,
      "number": 165,
      "title": "Offer option to list all commands in keybinding section",
      "user": {
        "login": "lee-dohm",
        "id": 1038121,
        "avatar_url": "https://avatars.githubusercontent.com/u/1038121?v=3",
        "gravatar_id": "",
        "url": "https://api.github.com/users/lee-dohm",
        "html_url": "https://github.com/lee-dohm",
        "followers_url": "https://api.github.com/users/lee-dohm/followers",
        "following_url": "https://api.github.com/users/lee-dohm/following{/other_user}",
        "gists_url": "https://api.github.com/users/lee-dohm/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/lee-dohm/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/lee-dohm/subscriptions",
        "organizations_url": "https://api.github.com/users/lee-dohm/orgs",
        "repos_url": "https://api.github.com/users/lee-dohm/repos",
        "events_url": "https://api.github.com/users/lee-dohm/events{/privacy}",
        "received_events_url": "https://api.github.com/users/lee-dohm/received_events",
        "type": "User",
        "site_admin": false
      "labels": [
          "url": "https://api.github.com/repos/atom/settings-view/labels/enhancement",
          "name": "enhancement",
          "color": "84b6eb"
      "state": "open",
      "locked": false,
      "assignee": null,
      "milestone": null,
      "comments": 3,
      "created_at": "2014-08-26T17:29:55Z",
      "updated_at": "2015-02-02T12:47:37Z",
      "closed_at": null,
      "body": "One of the hardest things for new users to Atom to discover is what commands are available if they have not yet had a keybinding set for them. This would allow them to set an option to more easily discover keybindings for commands that do not come with keybindings configured for them.\r\n\r\n## Requirements\r\n\r\n1. Create a `settings-view:showAllCommands` configuration option\r\n1. When `settings-view:showAllCommands` is set to `true`, show all commands in the Keybindings section whether they have a keybinding configured or not\r\n\r\n![keybinding sample](https://cloud.githubusercontent.com/assets/1038121/4048656/d3115568-2d45-11e4-8b07-02cfbaa42e7c.png)\r\n",
      "score": 10.900622
... snip ...

So, please, if you want help, we’re obviously willing to do our best to help. But you need to be much more specific about what exactly it is you want … and definitely less abusive.


I missed the AngularJS requirement. I’m not very knowledgeable about it, but maybe this works for you?


Maybe I’m still not clear. I thought there is already a way to do this on the real site when it is accessed via a normal browser. And I proposed to use the same way when using Atom Shell.

Perhaps it would also become clearer if you explained what you wanted to achieve by intercepting every Ajax request.


Thanks to everyone trying to help me.
I’m trying to explain my question, but it seems be failed because of my poor english.

Here is a example, it may be more clearer.

There is a website www.example.com.
It uses angularjs. It’s running now and I can’t modify it.
It has only a few pages, but make a lot of ajax request.

I want to get every ajax request/response data when I open the example.com in browser, and store them into files.
for example:
when the web browser loaded the data of url1 from server, the brower display it and then i store it into a file.
and url2 url3 … urlN. this means every ajax request.

Firstly, I tried to use jquery.ajaxComplete. And it works in some other websites, but not for the example.com. because the global option of every $.ajax is setted to false.

So I tried to make a desktop application using atom-shell. The atom-shell allows me to code for open site or other something. It seems be good way to me but only one important question:
when the example.com site is opening in atom-shell, the ajax request is fired, just like in other browers, how can I get the ajax request/response event in atom-shell, and get the event data?

I know the request module makes http request easier and it’s powerful. But it’s only for The foreseeable request. please note the example.com may be www.apple.com. most of the ajax request is unforeseen.


Ok, that’s a little more clear … but it probably needs more clarification. It sounds like what you want is for an application to:

  1. Load any web page, such as www.example.com
  2. Render and execute the code on the webpage just as a browser would
  3. As you interact with the web page
    1. Intercept any “AJAX” request being sent out
    2. Collect the responses returned
    3. Save those responses to a file

Is that correct?


Yes. That’s right.

Now the question is more shortly:
Is there a api for capture this event?


It seems to me you want to have a chat with @mark_hahn, he has built the “web-browser” package for Atom that will let a user open a website, perhaps he can tell you whether or not the thing you want is possible.


I have wrote a web crawler using request module one/two years ago.It’s so inefficient when analyzing the code.

Where can i find out the “web-browser” package?
Sorry, I’m new on this site.


OK, I’ve found it.
Thanks a lot.