jpillora / xhook

Easily intercept and modify XHR request and response
http://jpillora.com/xhook
MIT License
989 stars 158 forks source link

Invoking xhook from Angular 6/7 throws Illegal invocation exception #105

Closed sethurv closed 5 years ago

sethurv commented 5 years ago

When 'xhook' version 1.4.9 is included through index.html file in Angular 6, illegal invocation exception is thrown.

core.js:1633 ERROR TypeError: Illegal invocation
    at ZoneTask.scheduleTask [as scheduleFn] (zone.js:2964)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask (zone.js:407)
    at Object.onScheduleTask (zone.js:297)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask (zone.js:401)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.scheduleTask (zone.js:232)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.scheduleMacroTask (zone.js:255)
    at scheduleMacroTaskWithCurrentZone (zone.js:1114)
    at zone.js:3001
    at _global.<computed>.proto.<computed> [as send] (zone.js:1394)
    at Observable._subscribe (http.js:1639)

Similar issue is been raised in stackoverflow.

https://stackoverflow.com/questions/56451057/angular7-xhook-gives-error-typeerror-illegal-invocation

Anything to be done to avoid the error?

jpillora commented 5 years ago

Looks like zones does some monkey patching that is incompatible with xhooks monkey patching. Need someone who understands both to fix it.

On Thu, 1 Aug 2019 at 2:44 pm SetV notifications@github.com wrote:

When 'xhook' version 1.4.9 is included through index.html file in Angular 6, illegal invocation exception is thrown.

core.js:1633 ERROR TypeError: Illegal invocation at ZoneTask.scheduleTask [as scheduleFn] (zone.js:2964) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask (zone.js:407) at Object.onScheduleTask (zone.js:297) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask (zone.js:401) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.scheduleTask (zone.js:232) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.scheduleMacroTask (zone.js:255) at scheduleMacroTaskWithCurrentZone (zone.js:1114) at zone.js:3001 at _global..proto. [as send] (zone.js:1394) at Observable._subscribe (http.js:1639)

Similar issue is been raised in stackoverflow.

https://stackoverflow.com/questions/56451057/angular7-xhook-gives-error-typeerror-illegal-invocation

Anything to be done to avoid the error?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jpillora/xhook/issues/105?email_source=notifications&email_token=AAE2X44NJTP4URXVYMVOZKTQCJSZLA5CNFSM4IIMVRGKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HCXCPCA, or mute the thread https://github.com/notifications/unsubscribe-auth/AAE2X4ZUEX55UDBXDN7HFYTQCJSZLANCNFSM4IIMVRGA .

morsdyce commented 5 years ago

Does this happen only when used as a script tag? If you import it before angular does it work?

sethurv commented 5 years ago

I couldn't successfully import 'xhook'. Defined in 'package.json' and invoked import { xhook } from 'xhook';

"dependencies": {
  ...
  "xhook": "^1.4.9"
  ...
}

TypeError: Cannot read property 'before' of undefined error is thrown.

sethurv commented 5 years ago

Any update available? Do I need to move to an earlier version to make xhook to work?

morsdyce commented 5 years ago

I think your issue is that you try to import a named export instead of the default one. It should be import xhook from 'xhook'

I've setup an example repo with angular 7.2 which you can see is a working example: https://github.com/morsdyce/angular-xhook-reproduction-issue-105

sethurv commented 5 years ago

@morsdyce Thanks for your update. I can include xhook in Angular 6 now.