简体   繁体   English

通过Javascript控制台测试代理自动配置FindProxyForURL()

[英]Testing Proxy auto-config FindProxyForURL() via Javascript Console

Is it possible to test a Proxy auto-config (PAC) script by manually executing the FindProxyForURL(url, host) function from the browser JavaScript console? 是否可以通过从浏览器JavaScript控制台手动执行FindProxyForURL(url,host)函数来测试代理自动配置(PAC)脚本

Can the internal implementation of the PAC functions (such as dnsDomainIs, shExpMatch, isInNet) be accessed from the console? 是否可以从控制台访问PAC功能的内部实现(例如dnsDomainIs,shExpMatch,isInNet)?

Alternatively can these functions be implemented within standard JavaScript to allow the FindProxyForURL function to be executed manually? 或者,可以在标准JavaScript中实现这些功能,以允许手动执行FindProxyForURL函数吗?

The only way I can find to debug the proxy.pac script within the browser is to add alert() statements and let the browser execute it internally. 我可以找到的在浏览器中调试proxy.pac脚本的唯一方法是添加alert()语句并让浏览器在内部执行它。 Being able to add breakpoints and manually step through the FindProxyForURL function would make debugging it easier. 能够添加断点并手动执行FindProxyForURL函数将使调试变得更加容易。

There are many external tools for testing PAC scripts, such as pacparser (which uses Spidermonkey) and autoprox (which uses Microsofts implementation ) 有许多用于测试PAC脚本的外部工具,例如pacparser (使用Spidermonkey)和autoprox (使用Microsoft的实现

Similar questions have been asked: 有人问过类似的问题:

How to discover de proxy used in a pac 如何发现PAC中使用的代理
How to get access log of PAC(proxy auto config) 如何获取PAC的访问日志(代理自动配置)
Debugging autoproxy (PAC) javascript with alert()? 使用alert()调试自动代理(PAC)JavaScript吗?
Where in Windows is the Javascript file which contains functions for executing PAC files? Java文件在Windows中的哪里包含执行PAC文件的功能?

Some of the PAC functions have been implemented by pactester and available in pac_utils.js: https://github.com/manugarg/pactester/blob/master/pac_utils.js 一些PAC功能已由pactester实现,并在pac_utils.js中可用: https : //github.com/manugarg/pactester/blob/master/pac_utils.js

However it is missing the functions dnsResolve and myIpAddress as noted in the pactester readme : 但是,它缺少pactester自述文件中指出的dnsResolve和myIpAddress函数:

PAC files use certain JavaScript functions. PAC文件使用某些JavaScript函数。 These functions have been defined in pac_utils.js file included with this tool (This file was generated using another file from Mozilla source code). 这些功能已在该工具随附的pac_utils.js文件中定义(此文件是使用Mozilla源代码中的另一个文件生成的)。 Also, since JavaScript has no DNS resolving capability which is required by the "dnsResolve" and "myIpAddress" functions in the PAC files, these functions have been defined in perl and then exported to a JavaScript context. 另外,由于JavaScript没有PAC文件中的“ dnsResolve”和“ myIpAddress”功能所需的DNS解析功能,因此已在perl中定义了这些功能,然后将其导出到JavaScript上下文中。

There are implementations of these functions using web services but they won't work with local addresses without running your own server: 这些功能使用Web服务实现,但是如果不运行您自己的服务器,它们将无法与本地地址一起使用:

dnsResolve: dnsResolve:
Can I perform a DNS lookup (hostname to IP address) using client-side Javascript? 我可以使用客户端Javascript执行DNS查找(从主机名到IP地址)吗?
Perform a DNS lookup to resolve a hostname to an IP address using JavaScript 使用JavaScript执行DNS查找以将主机名解析为IP地址

myIpAddress: myIpAddress:
How to get client's IP address using javascript only? 如何仅使用javascript获取客户端的IP地址?

I don't know if it's possible to make any browsers grant access to manually execute scripts within the PAC sandbox environment which hosts the native implementation of these functions. 我不知道是否有可能使任何浏览器都授予访问权限,以在承载这些功能的本机实现的PAC沙箱环境中手动执行脚本。

PAC files run in a browser sandbox thus don't have access to the entire JavaScript programming language. PAC文件在浏览器沙箱中运行,因此无法访问整个JavaScript编程语言。 Instead, PAC file functionality is implemented in a browser with a custom sanboxed function set. 取而代之的是,PAC文件功能是在具有自定义盒装功能集的浏览器中实现的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM