diff --git a/README.md b/README.md
index 64e7a54..72a4b0c 100755
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ ajax-hook是用于拦截浏览器 XMLHttpRequest 对象的轻量库,它可以
## 更新记录
-2.1.2版本已发布,2.x和1.x最大的区别是添加了`proxy`方法且同时支持TypeScript,详请见[change list](./change-list.md) 。
+2.1.3已发布,2.x和1.x最大的区别是添加了`proxy`方法且同时支持TypeScript,详请见[change list](./change-list.md) 。
## 使用
@@ -18,7 +18,7 @@ ajax-hook是用于拦截浏览器 XMLHttpRequest 对象的轻量库,它可以
- CDN引入
```html
-
+
```
引入后会有一个名为"ah"(ajax hook)的全局对象,通过它可以调用ajax-hook的API,如`ah.proxy(hooks)`
diff --git a/dist/ajaxhook.core.min.js.map b/dist/ajaxhook.core.min.js.map
index 5d543cf..2dfcd28 100644
--- a/dist/ajaxhook.core.min.js.map
+++ b/dist/ajaxhook.core.min.js.map
@@ -1 +1 @@
-{"version":3,"sources":["webpack:///ajaxhook.core.min.js","webpack:///webpack/bootstrap 693b109ae617fd2c1d25?7b6c","webpack:///./src/xhr-hook.js?adec","webpack:///./src/cdn-core.js"],"names":["e","a","i","window","modules","__webpack_require__","moduleId","installedModules","exports","module","l","call","m","c","value","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","n","__esModule","object","property","prototype","hasOwnProperty","p","s","configEvent","event","xhrProxy","attr","target","currentTarget","hook","proxy","win","getterFactory","v","this","xhr","attrGetterHook","setterFactory","that","substring","attrSetterHook","hookFunction","fun","args","slice","arguments","ret","apply","realXhr","XMLHttpRequest","events","length","key","undefined","type","set","getProxy","assign","UNSENT","OPENED","HEADERS_RECEIVED","LOADING","DONE","unHook","_typeof","Symbol","iterator","obj","constructor","ah"],"mappings":"CAAC,SAASA,EAAGC,GAAK,IAAI,GAAIC,KAAKD,GAAGD,EAAEE,GAAKD,EAAEC,IAAMC,OAAiB,SAAUC,GCI1E,QAASC,GAAoBC,GAG5B,GAAGC,EAAiBD,GACnB,MAAOC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,MAAOlB,IAETJ,KAAKC,IAAMA,GAGbzB,OAAO+C,OAAO1B,EAAIkB,gBAAiBS,OAAQ,EAAGC,OAAQ,EAAGC,iBAAkB,EAAGC,QAAS,EAAGC,KAAM,IAuDzF/B,EAAIiB,GAGN,QAASe,GAAOhC,GACrBA,EAAMA,GAAOrC,OACTqC,EAAIiB,KAAUjB,EAAIkB,eAAiBlB,EAAIiB,IAC3CjB,EAAIiB,OAAWK,GFjDjB3C,OAAOC,eAAeZ,EAAS,cAC7BM,OAAO,GAGT,IAAI2D,GAA4B,kBAAXC,SAAoD,gBAApBA,QAAOC,SAAwB,SAAUC,GAAO,aAAcA,IAAS,SAAUA,GAAO,MAAOA,IAAyB,kBAAXF,SAAyBE,EAAIC,cAAgBH,QAAUE,IAAQF,OAAO9C,UAAY,eAAkBgD,GAEtQpE,GEtEgBwB,cFuEhBxB,EE/DgB8B,OFgEhB9B,EEsCgBgE,QAlHhB,IAAIf,GAAU,QAEHE,EAASA,EAATA,QAAU,OAAQ,UAAW,UAAW,QAAS,mBAAoB,UFyMzE,CAED,SAAUlD,EAAQD,EAASH,GAEjC,YAGAc,QAAOC,eAAeZ,EAAS,cAC7BM,OAAO,IAETN,EAAQsE,OAAKhB,EGtNb,WAEgBgB,GAALA,IACPxC,YACAkC","file":"ajaxhook.core.min.js","sourcesContent":["(function(e, a) { for(var i in a) e[i] = a[i]; }(window, /******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId]) {\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\ti: moduleId,\n/******/ \t\t\tl: false,\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.l = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// identity function for calling harmony imports with the correct context\n/******/ \t__webpack_require__.i = function(value) { return value; };\n/******/\n/******/ \t// define getter function for harmony exports\n/******/ \t__webpack_require__.d = function(exports, name, getter) {\n/******/ \t\tif(!__webpack_require__.o(exports, name)) {\n/******/ \t\t\tObject.defineProperty(exports, name, {\n/******/ \t\t\t\tconfigurable: false,\n/******/ \t\t\t\tenumerable: true,\n/******/ \t\t\t\tget: getter\n/******/ \t\t\t});\n/******/ \t\t}\n/******/ \t};\n/******/\n/******/ \t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t__webpack_require__.n = function(module) {\n/******/ \t\tvar getter = module && module.__esModule ?\n/******/ \t\t\tfunction getDefault() { return module['default']; } :\n/******/ \t\t\tfunction getModuleExports() { return module; };\n/******/ \t\t__webpack_require__.d(getter, 'a', getter);\n/******/ \t\treturn getter;\n/******/ \t};\n/******/\n/******/ \t// Object.prototype.hasOwnProperty.call\n/******/ \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(__webpack_require__.s = 2);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nexports.configEvent = configEvent;\nexports.hook = hook;\nexports.unHook = unHook;\n/*\n * author: wendux\n * email: 824783146@qq.com\n * source code: https://github.com/wendux/Ajax-hook\n */\n\n// Save original XMLHttpRequest as _rxhr\nvar realXhr = \"_rxhr\";\n\nvar events = exports.events = ['load', 'loadend', 'timeout', 'error', 'readystatechange', 'abort'];\n\nfunction configEvent(event, xhrProxy) {\n var e = {};\n for (var attr in event) {\n e[attr] = event[attr];\n } // xhrProxy instead\n e.target = e.currentTarget = xhrProxy;\n return e;\n}\n\nfunction hook(proxy, win) {\n win = win || window;\n // Avoid double hookAjax\n win[realXhr] = win[realXhr] || win.XMLHttpRequest;\n\n win.XMLHttpRequest = function () {\n\n // We shouldn't hookAjax XMLHttpRequest.prototype because we can't\n // guarantee that all attributes are on the prototype。\n // Instead, hooking XMLHttpRequest instance can avoid this problem.\n\n var xhr = new win[realXhr]();\n\n // Generate all callbacks(eg. onload) are enumerable (not undefined).\n for (var i = 0; i < events.length; ++i) {\n var key = 'on' + events[i];\n if (xhr[key] === undefined) xhr[key] = null;\n }\n\n for (var attr in xhr) {\n var type = \"\";\n try {\n type = _typeof(xhr[attr]); // May cause exception on some browser\n } catch (e) {}\n if (type === \"function\") {\n // hookAjax methods of xhr, such as `open`、`send` ...\n this[attr] = hookFunction(attr);\n } else {\n Object.defineProperty(this, attr, {\n get: getterFactory(attr),\n set: setterFactory(attr),\n enumerable: true\n });\n }\n }\n var that = this;\n xhr.getProxy = function () {\n return that;\n };\n this.xhr = xhr;\n };\n\n Object.assign(win.XMLHttpRequest, { UNSENT: 0, OPENED: 1, HEADERS_RECEIVED: 2, LOADING: 3, DONE: 4 });\n\n // Generate getter for attributes of xhr\n function getterFactory(attr) {\n return function () {\n var v = this.hasOwnProperty(attr + \"_\") ? this[attr + \"_\"] : this.xhr[attr];\n var attrGetterHook = (proxy[attr] || {})[\"getter\"];\n return attrGetterHook && attrGetterHook(v, this) || v;\n };\n }\n\n // Generate setter for attributes of xhr; by this we have an opportunity\n // to hookAjax event callbacks (eg: `onload`) of xhr;\n function setterFactory(attr) {\n return function (v) {\n var xhr = this.xhr;\n var that = this;\n var hook = proxy[attr];\n // hookAjax event callbacks such as `onload`、`onreadystatechange`...\n if (attr.substring(0, 2) === 'on') {\n that[attr + \"_\"] = v;\n xhr[attr] = function (e) {\n e = configEvent(e, that);\n var ret = proxy[attr] && proxy[attr].call(that, xhr, e);\n ret || v.call(that, e);\n };\n } else {\n //If the attribute isn't writable, generate proxy attribute\n var attrSetterHook = (hook || {})[\"setter\"];\n v = attrSetterHook && attrSetterHook(v, that) || v;\n this[attr + \"_\"] = v;\n try {\n // Not all attributes of xhr are writable(setter may undefined).\n xhr[attr] = v;\n } catch (e) {}\n }\n };\n }\n\n // Hook methods of xhr.\n function hookFunction(fun) {\n return function () {\n var args = [].slice.call(arguments);\n if (proxy[fun]) {\n var ret = proxy[fun].call(this, args, this.xhr);\n // If the proxy return value exists, return it directly,\n // otherwise call the function of xhr.\n if (ret) return ret;\n }\n return this.xhr[fun].apply(this.xhr, args);\n };\n }\n\n // Return the real XMLHttpRequest\n return win[realXhr];\n}\n\nfunction unHook(win) {\n win = win || window;\n if (win[realXhr]) win.XMLHttpRequest = win[realXhr];\n win[realXhr] = undefined;\n}\n\n/***/ }),\n/* 1 */,\n/* 2 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.ah = undefined;\n\nvar _xhrHook = __webpack_require__(0);\n\nvar ah = exports.ah = {\n hook: _xhrHook.hook,\n unHook: _xhrHook.unHook\n}; /*\n * author: wendux\n * email: 824783146@qq.com\n * source code: https://github.com/wendux/Ajax-hook\n */\n\n/***/ })\n/******/ ])));\n\n\n// WEBPACK FOOTER //\n// ajaxhook.core.min.js"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// identity function for calling harmony imports with the correct context\n \t__webpack_require__.i = function(value) { return value; };\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 693b109ae617fd2c1d25","/*\n * author: wendux\n * email: 824783146@qq.com\n * source code: https://github.com/wendux/Ajax-hook\n */\n\n// Save original XMLHttpRequest as _rxhr\nvar realXhr = \"_rxhr\"\n\nexport var events = ['load', 'loadend', 'timeout', 'error', 'readystatechange', 'abort'];\n\nexport function configEvent(event, xhrProxy) {\n var e = {};\n for (var attr in event) e[attr] = event[attr];\n // xhrProxy instead\n e.target = e.currentTarget = xhrProxy\n return e;\n}\n\nexport function hook(proxy, win) {\n win = win || window;\n // Avoid double hookAjax\n win[realXhr] = win[realXhr] || win.XMLHttpRequest\n\n win.XMLHttpRequest = function () {\n\n // We shouldn't hookAjax XMLHttpRequest.prototype because we can't\n // guarantee that all attributes are on the prototype。\n // Instead, hooking XMLHttpRequest instance can avoid this problem.\n\n var xhr = new win[realXhr];\n\n\n // Generate all callbacks(eg. onload) are enumerable (not undefined).\n for (var i = 0; i < events.length; ++i) {\n var key='on'+events[i];\n if (xhr[key] === undefined) xhr[key] = null;\n }\n\n for (var attr in xhr) {\n var type = \"\";\n try {\n type = typeof xhr[attr] // May cause exception on some browser\n } catch (e) {\n }\n if (type === \"function\") {\n // hookAjax methods of xhr, such as `open`、`send` ...\n this[attr] = hookFunction(attr);\n } else {\n Object.defineProperty(this, attr, {\n get: getterFactory(attr),\n set: setterFactory(attr),\n enumerable: true\n })\n }\n }\n var that = this;\n xhr.getProxy = function () {\n return that\n }\n this.xhr = xhr;\n }\n\n Object.assign(win.XMLHttpRequest, {UNSENT: 0, OPENED: 1, HEADERS_RECEIVED: 2, LOADING: 3, DONE: 4});\n\n // Generate getter for attributes of xhr\n function getterFactory(attr) {\n return function () {\n var v = this.hasOwnProperty(attr + \"_\") ? this[attr + \"_\"] : this.xhr[attr];\n var attrGetterHook = (proxy[attr] || {})[\"getter\"]\n return attrGetterHook && attrGetterHook(v, this) || v\n }\n }\n\n // Generate setter for attributes of xhr; by this we have an opportunity\n // to hookAjax event callbacks (eg: `onload`) of xhr;\n function setterFactory(attr) {\n return function (v) {\n var xhr = this.xhr;\n var that = this;\n var hook = proxy[attr];\n // hookAjax event callbacks such as `onload`、`onreadystatechange`...\n if (attr.substring(0, 2) === 'on') {\n that[attr + \"_\"] = v;\n xhr[attr] = function (e) {\n e = configEvent(e, that)\n var ret = proxy[attr] && proxy[attr].call(that, xhr, e)\n ret || v.call(that, e);\n }\n } else {\n //If the attribute isn't writable, generate proxy attribute\n var attrSetterHook = (hook || {})[\"setter\"];\n v = attrSetterHook && attrSetterHook(v, that) || v\n this[attr + \"_\"] = v;\n try {\n // Not all attributes of xhr are writable(setter may undefined).\n xhr[attr] = v;\n } catch (e) {\n }\n }\n }\n }\n\n // Hook methods of xhr.\n function hookFunction(fun) {\n return function () {\n var args = [].slice.call(arguments)\n if (proxy[fun]) {\n var ret = proxy[fun].call(this, args, this.xhr)\n // If the proxy return value exists, return it directly,\n // otherwise call the function of xhr.\n if (ret) return ret;\n }\n return this.xhr[fun].apply(this.xhr, args);\n }\n }\n\n // Return the real XMLHttpRequest\n return win[realXhr];\n}\n\nexport function unHook(win) {\n win = win || window\n if (win[realXhr]) win.XMLHttpRequest = win[realXhr];\n win[realXhr] = undefined;\n}\n\n\n\n\n\n// WEBPACK FOOTER //\n// ./src/xhr-hook.js","/*\n * author: wendux\n * email: 824783146@qq.com\n * source code: https://github.com/wendux/Ajax-hook\n */\n\nimport {hook, unHook} from \"./xhr-hook\";\n\nexport var ah = {\n hook,\n unHook,\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/cdn-core.js"],"sourceRoot":""}
\ No newline at end of file
+{"version":3,"sources":["webpack:///ajaxhook.core.min.js","webpack:///webpack/bootstrap 234a00c28fcb3f56e5b3?7d8d","webpack:///./src/xhr-hook.js?adec","webpack:///./src/cdn-core.js"],"names":["e","a","i","window","modules","__webpack_require__","moduleId","installedModules","exports","module","l","call","m","c","value","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","n","__esModule","object","property","prototype","hasOwnProperty","p","s","configEvent","event","xhrProxy","attr","target","currentTarget","hook","proxy","win","getterFactory","v","this","xhr","attrGetterHook","setterFactory","that","substring","attrSetterHook","hookFunction","fun","args","slice","arguments","ret","apply","realXhr","XMLHttpRequest","events","length","key","undefined","type","set","getProxy","assign","UNSENT","OPENED","HEADERS_RECEIVED","LOADING","DONE","unHook","_typeof","Symbol","iterator","obj","constructor","ah"],"mappings":"CAAC,SAASA,EAAGC,GAAK,IAAI,GAAIC,KAAKD,GAAGD,EAAEE,GAAKD,EAAEC,IAAMC,OAAiB,SAAUC,GCI1E,QAASC,GAAoBC,GAG5B,GAAGC,EAAiBD,GACnB,MAAOC,GAAiBD,GAAUE,OAGnC,IAAIC,GAASF,EAAiBD,IAC7BJ,EAAGI,EACHI,GAAG,EACHF,WAUD,OANAJ,GAAQE,GAAUK,KAAKF,EAAOD,QAASC,EAAQA,EAAOD,QAASH,GAG/DI,EAAOC,GAAI,EAGJD,EAAOD,QAvBf,GAAID,KA+DJ,OAnCAF,GAAoBO,EAAIR,EAGxBC,EAAoBQ,EAAIN,EAGxBF,EAAoBH,EAAI,SAASY,GAAS,MAAOA,IAGjDT,EAAoBU,EAAI,SAASP,EAASQ,EAAMC,GAC3CZ,EAAoBa,EAAEV,EAASQ,IAClCG,OAAOC,eAAeZ,EAASQ,GAC9BK,cAAc,EACdC,YAAY,EACZC,IAAKN,KAMRZ,EAAoBmB,EAAI,SAASf,GAChC,GAAIQ,GAASR,GAAUA,EAAOgB,WAC7B,WAAwB,MAAOhB,GAAgB,SAC/C,WAA8B,MAAOA,GAEtC,OADAJ,GAAoBU,EAAEE,EAAQ,IAAKA,GAC5BA,GAIRZ,EAAoBa,EAAI,SAASQ,EAAQC,GAAY,MAAOR,QAAOS,UAAUC,eAAelB,KAAKe,EAAQC,IAGzGtB,EAAoByB,EAAI,GAGjBzB,EAAoBA,EAAoB0B,EAAI,KDM/C,SAAUtB,EAAQD,EAASH,GAEjC,YE7DO,SAAS2B,GAAYC,EAAOC,GACjC,GAAIlC,KACJ,KAAK,GAAImC,KAAQF,GAAOjC,EAAEmC,GAAQF,EAAME,EAGxC,OADAnC,GAAEoC,OAASpC,EAAEqC,cAAgBH,EACtBlC,EAGF,QA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K,GAAI1B,KAAQS,GAAK,CACpB,GAAImB,GAAO,EACX,KACEA,IAAcnB,EAAIT,IAClB,MAAOnC,IAEI,aAAT+D,EAEFpB,KAAKR,GAAQe,EAAaf,GAE1BhB,OAAOC,eAAeuB,KAAMR,GAC1BZ,IAAKkB,EAAcN,GACnB6B,IAAKlB,EAAcX,GACnBb,YAAY,IAIlB,GAAIyB,GAAOJ,IACXC,GAAIqB,SAAW,WACb,MAAOlB,IAETJ,KAAKC,IAAMA,GAGbzB,OAAO+C,OAAO1B,EAAIkB,gBAAiBS,OAAQ,EAAGC,OAAQ,EAAGC,iBAAkB,EAAGC,QAAS,EAAGC,KAAM,IAuDzF/B,EAAIiB,GAGN,QAASe,GAAOhC,GACrBA,EAAMA,GAAOrC,OACTqC,EAAIiB,KAAUjB,EAAIkB,eAAiBlB,EAAIiB,IAC3CjB,EAAIiB,OAAWK,GFjDjB3C,OAAOC,eAAeZ,EAAS,cAC7BM,OAAO,GAGT,IAAI2D,GAA4B,kBAAXC,SAAoD,gBAApBA,QAAOC,SAAwB,SAAUC,GAAO,aAAcA,IAAS,SAAUA,GAAO,MAAOA,IAAyB,kBAAXF,SAAyBE,EAAIC,cAAgBH,QAAUE,IAAQF,OAAO9C,UAAY,eAAkBgD,GAEtQpE,GEtEgBwB,cFuEhBxB,EE/DgB8B,OFgEhB9B,EEsCgBgE,QAlHhB,IAAIf,GAAU,QAEHE,EAASA,EAATA,QAAU,OAAQ,UAAW,UAAW,QAAS,mBAAoB,UFyMzE,CAED,SAAUlD,EAAQD,EAASH,GAEjC,YAGAc,QAAOC,eAAeZ,EAAS,cAC7BM,OAAO,IAETN,EAAQsE,OAAKhB,EGtNb,WAEgBgB,GAALA,IACPxC,YACAkC","file":"ajaxhook.core.min.js","sourcesContent":["(function(e, a) { for(var i in a) e[i] = a[i]; }(window, /******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId]) {\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\ti: moduleId,\n/******/ \t\t\tl: false,\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.l = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// identity function for calling harmony imports with the correct context\n/******/ \t__webpack_require__.i = function(value) { return value; };\n/******/\n/******/ \t// define getter function for harmony exports\n/******/ \t__webpack_require__.d = function(exports, name, getter) {\n/******/ \t\tif(!__webpack_require__.o(exports, name)) {\n/******/ \t\t\tObject.defineProperty(exports, name, {\n/******/ \t\t\t\tconfigurable: false,\n/******/ \t\t\t\tenumerable: true,\n/******/ \t\t\t\tget: getter\n/******/ \t\t\t});\n/******/ \t\t}\n/******/ \t};\n/******/\n/******/ \t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t__webpack_require__.n = function(module) {\n/******/ \t\tvar getter = module && module.__esModule ?\n/******/ \t\t\tfunction getDefault() { return module['default']; } :\n/******/ \t\t\tfunction getModuleExports() { return module; };\n/******/ \t\t__webpack_require__.d(getter, 'a', getter);\n/******/ \t\treturn getter;\n/******/ \t};\n/******/\n/******/ \t// Object.prototype.hasOwnProperty.call\n/******/ \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(__webpack_require__.s = 2);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nexports.configEvent = configEvent;\nexports.hook = hook;\nexports.unHook = unHook;\n/*\n * author: wendux\n * email: 824783146@qq.com\n * source code: https://github.com/wendux/Ajax-hook\n */\n\n// Save original XMLHttpRequest as _rxhr\nvar realXhr = \"_rxhr\";\n\nvar events = exports.events = ['load', 'loadend', 'timeout', 'error', 'readystatechange', 'abort'];\n\nfunction configEvent(event, xhrProxy) {\n var e = {};\n for (var attr in event) {\n e[attr] = event[attr];\n } // xhrProxy instead\n e.target = e.currentTarget = xhrProxy;\n return e;\n}\n\nfunction hook(proxy, win) {\n win = win || window;\n // Avoid double hookAjax\n win[realXhr] = win[realXhr] || win.XMLHttpRequest;\n\n win.XMLHttpRequest = function () {\n\n // We shouldn't hookAjax XMLHttpRequest.prototype because we can't\n // guarantee that all attributes are on the prototype。\n // Instead, hooking XMLHttpRequest instance can avoid this problem.\n\n var xhr = new win[realXhr]();\n\n // Generate all callbacks(eg. onload) are enumerable (not undefined).\n for (var i = 0; i < events.length; ++i) {\n var key = 'on' + events[i];\n if (xhr[key] === undefined) xhr[key] = null;\n }\n\n for (var attr in xhr) {\n var type = \"\";\n try {\n type = _typeof(xhr[attr]); // May cause exception on some browser\n } catch (e) {}\n if (type === \"function\") {\n // hookAjax methods of xhr, such as `open`、`send` ...\n this[attr] = hookFunction(attr);\n } else {\n Object.defineProperty(this, attr, {\n get: getterFactory(attr),\n set: setterFactory(attr),\n enumerable: true\n });\n }\n }\n var that = this;\n xhr.getProxy = function () {\n return that;\n };\n this.xhr = xhr;\n };\n\n Object.assign(win.XMLHttpRequest, { UNSENT: 0, OPENED: 1, HEADERS_RECEIVED: 2, LOADING: 3, DONE: 4 });\n\n // Generate getter for attributes of xhr\n function getterFactory(attr) {\n return function () {\n var v = this.hasOwnProperty(attr + \"_\") ? this[attr + \"_\"] : this.xhr[attr];\n var attrGetterHook = (proxy[attr] || {})[\"getter\"];\n return attrGetterHook && attrGetterHook(v, this) || v;\n };\n }\n\n // Generate setter for attributes of xhr; by this we have an opportunity\n // to hookAjax event callbacks (eg: `onload`) of xhr;\n function setterFactory(attr) {\n return function (v) {\n var xhr = this.xhr;\n var that = this;\n var hook = proxy[attr];\n // hookAjax event callbacks such as `onload`、`onreadystatechange`...\n if (attr.substring(0, 2) === 'on') {\n that[attr + \"_\"] = v;\n xhr[attr] = function (e) {\n e = configEvent(e, that);\n var ret = proxy[attr] && proxy[attr].call(that, xhr, e);\n ret || v.call(that, e);\n };\n } else {\n //If the attribute isn't writable, generate proxy attribute\n var attrSetterHook = (hook || {})[\"setter\"];\n v = attrSetterHook && attrSetterHook(v, that) || v;\n this[attr + \"_\"] = v;\n try {\n // Not all attributes of xhr are writable(setter may undefined).\n xhr[attr] = v;\n } catch (e) {}\n }\n };\n }\n\n // Hook methods of xhr.\n function hookFunction(fun) {\n return function () {\n var args = [].slice.call(arguments);\n if (proxy[fun]) {\n var ret = proxy[fun].call(this, args, this.xhr);\n // If the proxy return value exists, return it directly,\n // otherwise call the function of xhr.\n if (ret) return ret;\n }\n return this.xhr[fun].apply(this.xhr, args);\n };\n }\n\n // Return the real XMLHttpRequest\n return win[realXhr];\n}\n\nfunction unHook(win) {\n win = win || window;\n if (win[realXhr]) win.XMLHttpRequest = win[realXhr];\n win[realXhr] = undefined;\n}\n\n/***/ }),\n/* 1 */,\n/* 2 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.ah = undefined;\n\nvar _xhrHook = __webpack_require__(0);\n\nvar ah = exports.ah = {\n hook: _xhrHook.hook,\n unHook: _xhrHook.unHook\n}; /*\n * author: wendux\n * email: 824783146@qq.com\n * source code: https://github.com/wendux/Ajax-hook\n */\n\n/***/ })\n/******/ ])));\n\n\n// WEBPACK FOOTER //\n// ajaxhook.core.min.js"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// identity function for calling harmony imports with the correct context\n \t__webpack_require__.i = function(value) { return value; };\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 234a00c28fcb3f56e5b3","/*\n * author: wendux\n * email: 824783146@qq.com\n * source code: https://github.com/wendux/Ajax-hook\n */\n\n// Save original XMLHttpRequest as _rxhr\nvar realXhr = \"_rxhr\"\n\nexport var events = ['load', 'loadend', 'timeout', 'error', 'readystatechange', 'abort'];\n\nexport function configEvent(event, xhrProxy) {\n var e = {};\n for (var attr in event) e[attr] = event[attr];\n // xhrProxy instead\n e.target = e.currentTarget = xhrProxy\n return e;\n}\n\nexport function hook(proxy, win) {\n win = win || window;\n // Avoid double hookAjax\n win[realXhr] = win[realXhr] || win.XMLHttpRequest\n\n win.XMLHttpRequest = function () {\n\n // We shouldn't hookAjax XMLHttpRequest.prototype because we can't\n // guarantee that all attributes are on the prototype。\n // Instead, hooking XMLHttpRequest instance can avoid this problem.\n\n var xhr = new win[realXhr];\n\n\n // Generate all callbacks(eg. onload) are enumerable (not undefined).\n for (var i = 0; i < events.length; ++i) {\n var key='on'+events[i];\n if (xhr[key] === undefined) xhr[key] = null;\n }\n\n for (var attr in xhr) {\n var type = \"\";\n try {\n type = typeof xhr[attr] // May cause exception on some browser\n } catch (e) {\n }\n if (type === \"function\") {\n // hookAjax methods of xhr, such as `open`、`send` ...\n this[attr] = hookFunction(attr);\n } else {\n Object.defineProperty(this, attr, {\n get: getterFactory(attr),\n set: setterFactory(attr),\n enumerable: true\n })\n }\n }\n var that = this;\n xhr.getProxy = function () {\n return that\n }\n this.xhr = xhr;\n }\n\n Object.assign(win.XMLHttpRequest, {UNSENT: 0, OPENED: 1, HEADERS_RECEIVED: 2, LOADING: 3, DONE: 4});\n\n // Generate getter for attributes of xhr\n function getterFactory(attr) {\n return function () {\n var v = this.hasOwnProperty(attr + \"_\") ? this[attr + \"_\"] : this.xhr[attr];\n var attrGetterHook = (proxy[attr] || {})[\"getter\"]\n return attrGetterHook && attrGetterHook(v, this) || v\n }\n }\n\n // Generate setter for attributes of xhr; by this we have an opportunity\n // to hookAjax event callbacks (eg: `onload`) of xhr;\n function setterFactory(attr) {\n return function (v) {\n var xhr = this.xhr;\n var that = this;\n var hook = proxy[attr];\n // hookAjax event callbacks such as `onload`、`onreadystatechange`...\n if (attr.substring(0, 2) === 'on') {\n that[attr + \"_\"] = v;\n xhr[attr] = function (e) {\n e = configEvent(e, that)\n var ret = proxy[attr] && proxy[attr].call(that, xhr, e)\n ret || v.call(that, e);\n }\n } else {\n //If the attribute isn't writable, generate proxy attribute\n var attrSetterHook = (hook || {})[\"setter\"];\n v = attrSetterHook && attrSetterHook(v, that) || v\n this[attr + \"_\"] = v;\n try {\n // Not all attributes of xhr are writable(setter may undefined).\n xhr[attr] = v;\n } catch (e) {\n }\n }\n }\n }\n\n // Hook methods of xhr.\n function hookFunction(fun) {\n return function () {\n var args = [].slice.call(arguments)\n if (proxy[fun]) {\n var ret = proxy[fun].call(this, args, this.xhr)\n // If the proxy return value exists, return it directly,\n // otherwise call the function of xhr.\n if (ret) return ret;\n }\n return this.xhr[fun].apply(this.xhr, args);\n }\n }\n\n // Return the real XMLHttpRequest\n return win[realXhr];\n}\n\nexport function unHook(win) {\n win = win || window\n if (win[realXhr]) win.XMLHttpRequest = win[realXhr];\n win[realXhr] = undefined;\n}\n\n\n\n\n\n// WEBPACK FOOTER //\n// ./src/xhr-hook.js","/*\n * author: wendux\n * email: 824783146@qq.com\n * source code: https://github.com/wendux/Ajax-hook\n */\n\nimport {hook, unHook} from \"./xhr-hook\";\n\nexport var ah = {\n hook,\n unHook,\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/cdn-core.js"],"sourceRoot":""}
\ No newline at end of file
diff --git a/dist/ajaxhook.js b/dist/ajaxhook.js
index 36979a2..f5a53b4 100644
--- a/dist/ajaxhook.js
+++ b/dist/ajaxhook.js
@@ -426,7 +426,7 @@ function Proxy(proxy, win) {
setRequestHeader: function setRequestHeader(args, xhr) {
// Collect request headers
xhr.config.headers[args[0].toLowerCase()] = args[1];
- return true;
+ if (onRequest) return true;
},
addEventListener: function addEventListener(args, xhr) {
var _this = this;
diff --git a/dist/ajaxhook.min.js b/dist/ajaxhook.min.js
index 1a9d803..aff0046 100644
--- a/dist/ajaxhook.min.js
+++ b/dist/ajaxhook.min.js
@@ -1,2 +1,2 @@
-!function(t,e){for(var n in e)t[n]=e[n]}(window,function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=3)}([function(t,e,n){"use strict";function r(t,e){var n={};for(var r in t)n[r]=t[r];return n.target=n.currentTarget=e,n}function o(t,e){function n(e){return function(){var n=this.hasOwnProperty(e+"_")?this[e+"_"]:this.xhr[e],r=(t[e]||{}).getter;return r&&r(n,this)||n}}function o(e){return function(n){var o=this.xhr,s=this,i=t[e];if("on"===e.substring(0,2))s[e+"_"]=n,o[e]=function(i){i=r(i,s),t[e]&&t[e].call(s,o,i)||n.call(s,i)};else{var u=(i||{}).setter;n=u&&u(n,s)||n,this[e+"_"]=n;try{o[e]=n}catch(t){}}}}function s(e){return function(){var n=[].slice.call(arguments);if(t[e]){var r=t[e].call(this,n,this.xhr);if(r)return r}return this.xhr[e].apply(this.xhr,n)}}return e=e||window,e[u]=e[u]||e.XMLHttpRequest,e.XMLHttpRequest=function(){for(var t=new e[u],r=0;r