使用alert() 调试autoproxy (PAC) javascript?

发布于 2024-07-24 17:36:39 字数 188 浏览 4 评论 0原文

我正在编写一个与 Firefox 一起使用的自定义 .pac 脚本。 根据我见过的大量示例,我散布了警报()以对其进行调试,但没有警报弹出,即使该脚本显然正在被调用。 (每次更改脚本后,我都会在“连接设置”中单击“重新加载”。我什至尝试过重新启动 Firefox。)

警报应该在 PAC 脚本中起作用吗? 也许这是 IE 独有的功能?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

待天淡蓝洁白时 2024-07-31 17:36:39
  1. .pac 文件中使用 alert 函数。

    • Firefox 浏览器中:

      工具 -> 网络开发人员 -> 浏览器控制台 (Ctrl+Shift+J) [这不是 Web 控制台!!] -> 过滤器输出:PAC-alert

    • Chrome 浏览器中:

      转到chrome://net-internals/#events -> 搜索带有描述的记录:PAC_JAVASCRIPT_ALERT

      (关于 Chrome,感谢此答案


示例 .pac 文件:

function FindProxyForURL(url, host) {
    alert("url = " + url + " *** host = " + host + " *** Resolved IP = " + dnsResolve(host));

    return "DIRECT";
}
  1. Use alert function in your .pac file.

    • In Firefox Browser:

      Tools -> Web Developer -> Browser Console (Ctrl+Shift+J) [This is not Web Console!!] -> Filter output: PAC-alert

    • In Chrome Browser:

      Go to chrome://net-internals/#events -> Search for a record with description: PAC_JAVASCRIPT_ALERT

      (About Chrome, thank this answer)


Sample .pac file:

function FindProxyForURL(url, host) {
    alert("url = " + url + " *** host = " + host + " *** Resolved IP = " + dnsResolve(host));

    return "DIRECT";
}
素衣风尘叹 2024-07-31 17:36:39

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

将警报函数添加到沙箱中:

80         // add predefined functions to 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     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     }

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     }
酷炫老祖宗 2024-07-31 17:36:39

啊哈! 警报消息正在记录到控制台。 无论如何,我实际上更喜欢用它来提醒弹出窗口。

Ah Ha! The alert messages are getting logged to the console. I actually prefer that to alert popups anyway.

月亮是我掰弯的 2024-07-31 17:36:39

您可能需要在 Windows 注册表中禁用“EnableAutoproxyResultCache”。 。 。

You might need to disable "EnableAutoproxyResultCache" in the Windows registry . . .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文