jneander jneander -3 years ago 127
Javascript Question

Prevent zombie.js from loading only external resources

I am using zombie.js to load a page from a local express server during a test. Unfortunately, there is a script element which calls out to Google Analytics. I would like to block this external script (gracefully) without preventing other (local) scripts from loading, if possible.

I know that

{ runScripts : false }
is available with calls to
. However, that refuses to load any and all scripts on the page, not just those living on other hosts. Is this possible?

Answer Source

You should use the resources object.

You can set certain requests to give specific responses if you don't want the request to actually go through. You'd do the following to make google analytics return an empty document:


Note that you have to provide the exact URL that you want to mock, there is no way to mock a partial URL such as a domain name.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download