如何调试PAC文件(How do I debug PAC file)?
Table of Contents
由于我使用的是Mac,这里以macOS为例,Windows应该是类似的。
I’m using macOS, but I guess it should be similar in Windows.
需要准备的东西(Things you should prepare)
一个你准备要调试的PAC文件(把以下内容保存到proxy.pac
里,就是一个最简单的PAC文件了)
A PAC file that you want to debug(save the following code to proxy.pac
file and now you’ve got a simplest PAC file)
function FindProxyForURL(url, host) {
alert(url)
return DIRECT;
}
一个火狐浏览器:没错,我们要用火狐浏览器来调试PAC文件。
A Firefox browser: yep, we are gonna use Firefox browser to debug PAC file.
配置火狐浏览器使用PAC文件(Let Firefox use our PAC)
打开火狐浏览器,把前面保存的PAC文件拖到火狐浏览器上,它会自动打开PAC文件,我们可以看到浏览器地址栏上有文件的地址,这个地址在下边会用到。
Open Firefox, drag the PAC file to Firefox and Firefox will open the PAC file, we can see an address in the address bar, we’re gonna use this address below.
打开火狐浏览器→首选项
→常规
→滚动到底部可以看到网络设置
→点击设置...
Open Firefox browser→Preferences
→General
→scroll to the bottom and you can see Network Settings
→click Settings...
选择“自动代理配置的URL(PAC)”,并填放前面获取到的PAC文件路径,然后点击确定
Select “Automatic proxy configuration URL” and input the URL we got above(mine is file:///Users/bruce/Downloads/proxy.pac
) then click OK
.
注意:每次修改PAC文件后,都要点击重新载入
,浏览器才会使用新的PAC文件。
Attention: once you have modified your PAC file, you need click reload
button to reload it.
开始debug(Let’s get start)
点击火狐浏览器顶部菜单栏的工具
→Web开发者
→浏览器控制台
(注意,是浏览器控制台,不是Web控制台)
In the top menu bar of Firefox, click Tools
→Web Developer
→Browser Console
(Attention: it’s Browser Console, not Web Console)
访问任意网站,比如https://www.google.com
,即可在浏览器控制台中看到以PAC-alert:
开头的域名,其实这就是PAC文件中alert出来的,其实还会有其它信息,我们可以输入PAC
来过滤出只包含PAC开头的信息。
Visit any website, for example https://www.google.com
, then we can see the urls prefixed with PAC-alert:
on the browser console which was alert from PAC file. Actually there are other info, we can input PAC
to filter out what we need(prefixed with PAC)
至此,你已经知道怎么用火狐浏览器来调试PAC文件了,开始你的调试吧。
Now you know how to debug a PAC file with Firefox Browser, enjoy!