防止zombie.js仅加载外部资源 [英] Prevent zombie.js from loading only external resources

查看:99
本文介绍了防止zombie.js仅加载外部资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在测试期间,我正在使用zombie.js从本地快递服务器加载页面。不幸的是,有一个脚本元素调用Google Analytics(分析)。如果可能,我想阻止这个外部脚本(优雅),而不会阻止其他(本地)脚本加载。

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.

我知道 {runScripts :false} 可以调用 browser.visit()。但是,它拒绝加载页面上的所有脚本,而不仅仅是生活在其他主机上的脚本。这是可能的吗?

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

推荐答案

你应该使用 resources 对象。

您可以设置特定请求,您不希望请求真正地通过。您可以执行以下操作,使Google Analytics(分析)返回一个空白文档:

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:

browser.resources.mock('http://google.com/url/to/analytics.js',{});

请注意,您必须提供要嘲笑的确切网址,没有办法模拟部分网址,如域名。

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.

这篇关于防止zombie.js仅加载外部资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆