{"id":13447314,"url":"https://github.com/mobify/hijax","last_synced_at":"2025-03-21T17:31:14.572Z","repository":{"id":17104457,"uuid":"19870130","full_name":"mobify/hijax","owner":"mobify","description":"XHR Proxy to intercept AJAX calls independent of libraries.","archived":true,"fork":false,"pushed_at":"2016-09-27T22:46:21.000Z","size":2252,"stargazers_count":13,"open_issues_count":5,"forks_count":2,"subscribers_count":80,"default_branch":"develop","last_synced_at":"2025-03-01T09:41:16.648Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mobify.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-16T20:41:16.000Z","updated_at":"2023-01-28T13:24:51.000Z","dependencies_parsed_at":"2022-08-04T16:30:33.435Z","dependency_job_id":null,"html_url":"https://github.com/mobify/hijax","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobify%2Fhijax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobify%2Fhijax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobify%2Fhijax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobify%2Fhijax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mobify","download_url":"https://codeload.github.com/mobify/hijax/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244541971,"owners_count":20469244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T05:01:13.649Z","updated_at":"2025-03-21T17:31:12.151Z","avatar_url":"https://github.com/mobify.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Hijax XHR Proxy\n\n[![NPM](https://nodei.co/npm/hijax.png?downloads=true\u0026stars=true)](https://nodei.co/npm/hijax/)\n\nHijax is meant to be a lightweight library-independent way of intercepting XHR\nrequests. It is meant to be used with the\n[Mobify Adaptive](https://github.com/mobify/adaptivejs) and\n[MobifyJS](https://github.com/mobify/mobifyjs) frameworks.\n\n## Browser support\nHijax has been tested on the following browsers:\n\n- Chrome (mobile and desktop)\n- Firefox (desktop)\n- Safari (desktop and iOS6+)\n\n## Library support\nAlthough Hijax should intercept XHR requests regardless of how the XHR request\nis invoked, its proxying features are known only to work with the following\nlibraries at present:\n\n- jQuery 2.1.1, 1.3.2\n- Zepto 1.1\n\nHijax *should* be able to work with other libraries, but support isn't\nguaranteed.\n\n## Adapters\nSupport for proxying other libraries can be added with the use of adapters, as\nshown in the example in the `example` folder, which uses an adapter for jQuery\n1.3.2 from the `adapter` folder.\n\n## How to use Hijax\nImport Hijax distribution file from the `dist` folder (and any adapters you\nneed) into your project. Hijax uses an UMD format, but AMD is the preferred way\nof using Hijax.\n\nHijax is initialized by creating a hijax instance like so:\n\n    var hijax = new Hijax();\n\nIf an adapter is used, it should be passed to the constructor:\n\n    // Eg:\n    var myAdapter = require('adapters/jquery.legacy');\n    var hijax = new Hijax(myAdapter);\n\nAn XHR request can be proxied by calling the `set` method, and providing a name,\nurl/truth function and the callbacks for the events to be proxied:\n\n    hijax.set(\u003cname\u003e, \u003curl\u003e OR \u003cfunction\u003e, {\n        beforeSend: \u003cfunction\u003e,\n        receive: \u003cfunction\u003e,\n        complete: \u003cfunction\u003e\n    });\n\n    // Eg:\n    hijax\n        .set(\n            // A unique name for the proxy\n            'homeProxy',\n            // Either a URL, or a function that takes in the URL as an argument,\n            // and returns true/false\n            '/example/response.json',\n            {\n            // Request is being sent\n            beforeSend: function(xhr) {\n                console.log(this.name, 'Intercepting send.');\n            },\n            // Received response data\n            receive: function(data, xhr) {\n                console.log(this.name, 'Intercepting receive.');\n            },\n            // Request completed (desktop listener has finished processing it)\n            complete: function(data, xhr) {\n                console.log(this.name, 'Request complete.');\n            }\n        });\n\nAdditional listeners can be set like so:\n\n    hijax.addListener(\u003cname\u003e, \u003cevent\u003e, \u003ccallback\u003e);\n\n    // Eg:\n    hijax.addListener('proxy1', 'complete', function(data, xhr) {\n        console.log(this.name, 'Another listener.');\n    });\n\nYou can remove listeners on a given instance like so:\n\n    hijax.removeListener(\u003cname\u003e, \u003cevent\u003e);\n\n    // Eg:\n    var cb = function() { ... }\n    hijax.removeListener('proxy1', 'beforeSend', cb);\n\n    // Removes all listeners on the beforeSend event\n    hijax.removeListener('proxy', 'beforeSend');\n\n## Data Parsers\nHijax will attempt to detect the type of data by reading the response header. If\nthe response is available in the respective format (for instance, responseJSON\nfor a json content type), Hijax will just pipe it through.\n\nIn other instances, Hijax will attempt to use a data parser to parse the data\ninto a usable format. Currently only JSON is parsed (using the browser's native\nJSON.parse method). Text, HTML and XML are piped through a stub parser which\ndoes not modify the data.\n\nYou can override the parsers by passing it in the options when creating an\ninstance:\n\n    hijax.set(\u003cname\u003e, \u003curl\u003e OR \u003cfunction\u003e, { ... }, {\n        dataParsers: { ... }\n    });\n\n    // Eg:\n    hijax.set('homeProxy', '/home.html', {\n        complete: function(data) {\n            // ...\n        }\n    }, {\n        dataParsers: {\n            // When receiving HTML content, invoke this callback\n            html: function(data) {\n                return data;\n            }\n        }\n    });\n\n## Development\n\nDeveloping Hijax locally involves:\n```bash\n# Grab dev dependencies\nnpm install\n./node_modules/.bin/bower install\n```\n\nCheck out some of the example usages in `examples/`\n\nBuilding `dist/` code:\n\nRun `grunt` or `grunt build`\n\nOpen a PR!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmobify%2Fhijax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmobify%2Fhijax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmobify%2Fhijax/lists"}