用alert()调试自动代理(PAC)的JavaScript? [英] Debugging autoproxy (PAC) javascript with alert()?

查看:373
本文介绍了用alert()调试自动代理(PAC)的JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个用于Firefox的自定义.pac脚本。以下我见过的众多例子中,为了调试alert(),我忽略了alert(),但是没有警报弹出,即使脚本显然被调用。 (我在点击连接设置中的重新加载后,每次改变我的脚本,我甚至尝试重新启动Firefox。)



警报应该从PAC脚本?也许这是一个IE浏览器的功能?

http://mxr.mozilla.org/mozilla-central/source/netwerk/base/src/nsProxyAutoConfig.js



警报函数被添加到沙盒中:

  80 / /将预定义函数添加到pac 
81 this._sandBox.importFunction(myIpAddress);
82 this._sandBox.importFunction(dnsResolve);
83 this._sandBox.importFunction(proxyAlert,alert);

映射的函数调用转储到错误控制台的dump:

  108 function proxyAlert(msg){
109 msg = XPCSafeJSObjectWrapper(msg);
110尝试{
111 //看来控制台服务是线程安全的。
112 var cns = Components.classes [@ mozilla.org/consoleservice;1]
113 .getService(Components.interfaces.nsIConsoleService);
114 cns.logStringMessage(PAC-alert:+ msg);
115} catch(e){
116 dump(PAC:proxyAlert ERROR:+ e +\\\
);
117}


I am writing a custom .pac script for use with Firefox. Following numerous examples I've seen, I intersperse alert()s in order to debug it, but no alerts popup, even though the script is clearly being invoked. (I am clicking "Reload" in the "Connection settings" after each change to my script. I have even tried restarting Firefox.)

Are alerts supposed to work from PAC scripts? Maybe this is an IE-only feature?

解决方案

http://mxr.mozilla.org/mozilla-central/source/netwerk/base/src/nsProxyAutoConfig.js

The alert function is added to the sandbox:

80         // add predefined functions to pac
81         this._sandBox.importFunction(myIpAddress);
82         this._sandBox.importFunction(dnsResolve);
83         this._sandBox.importFunction(proxyAlert, "alert");

And the mapped function calls dump, which goes to the Error Console:

108 function proxyAlert(msg) {
109     msg = XPCSafeJSObjectWrapper(msg);
110     try {
111         // It would appear that the console service is threadsafe.
112         var cns = Components.classes["@mozilla.org/consoleservice;1"]
113                             .getService(Components.interfaces.nsIConsoleService);
114         cns.logStringMessage("PAC-alert: "+msg);
115     } catch (e) {
116         dump("PAC: proxyAlert ERROR: "+e+"\n");
117     }

这篇关于用alert()调试自动代理(PAC)的JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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