本文介绍了有没有办法让Fiddler JS格式化程序扩展有条件地工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为JS开发人员,我经常使用Fiddler工具.我还使用其插件 JavaScript格式化程序来很好地格式化缩小文件以进行调试.

As a JS dev, I very frequently use Fiddler tool. I also use its addon JavaScript Formatter to nicely format minified files for debugging purposes.

但是,问题在于JS格式化程序似乎根本不是可配置的,并且可以在全有或全无"的基础上工作.

However, the problem is that the JS formatter doesn't seem to be configurable at all, and works on "all-or-nothing" base.

问题:

在我的公司中,有时我们将很多(不是JS,但可编译为JS)文件捆绑在一起,用作JS,然后依靠该文件格式来解析它们并正确加载.这听起来可能很奇怪,但是这是为了避免拥有数十个微型文件,并且将所有微型文件捆绑在一起.

In my company, we sometimes bundle a lot of (not JS, but compilable to JS) files together, serve it as JS, and then, rely on that file format to parse them and load properly. This may sound strange, but it's to avoid having tens of micro files, and have a one bundle with all of them.

所以基本上,文件看起来像:

So basically, the file looks like:

//MAGICCOMMENT
//FILEID
markup
markup
...
markup
//FILEID
markup
markup
...
markup

以此类推.

问题:

有什么办法告诉提琴手不要美化这些文件吗?我们在第一行中有一个//MAGICCOMMENT,对于所有的多部分文件来说都是相同的,也许可以用来检测它,但是我不知道是否以及如何使用它.

Is there any way to tell Fiddler not to prettify that files? We have a //MAGICCOMMENT in the first line, which is the same for all the multipart files, which can perhaps be used to detect it, but I don't know if and how can I make use of it.

PS:我想我们不能更改所提供文件的MIME类型.

PS: I guess we can't change the MIME type of the served files.

我知道Rules菜单中的使JavaScript变得漂亮"选项,该选项是在安装JS Formatter插件后添加的.我想使此选项有条件地起作用(但是:在将数据发送到浏览器时,所以我可以将断点放在美化的JS源上的浏览器中,用于所有想要的文件美化,即除多部分以外的文件.

I know the "Make JavaScript Pretty" option in Rules menu, which is added after installing the JS Formatter plugin. I want to make this option working conditionally (but: at the time of sending data to the browser, so I can put breakpoints in the browser on the prettified JS source, for all the files that I want to be prettified, i.e. the files other than the multiparts).

推荐答案

现在,您只需在Fiddler Rules菜单上禁用使JavaScript变得漂亮"即可.如果要美化单个JavaScript文件,可以通过右键单击"Web会话"列表中的会话,然后直接在会话上选择使JavaScript变得漂亮"来实现.

For now, you can just disable the "Make JavaScript Pretty" item on the Fiddler Rules menu. When you want to beautify an individual JavaScript file, you can do so by right-clicking the session in the Web Sessions list and choosing Make JavaScript Pretty directly on the session.

或者,您可以禁用全局选项,并让FiddlerScript有条件地格式化JS文件.例如.内部规则>自定义规则> OnPeekAtResponseHeaders()

Alternatively, you can disable the global option and have FiddlerScript conditionally format the JS File. E.g. inside Rules > Customize Rules > OnPeekAtResponseHeaders()

if (oSession.oResponse["Content-Type"].ToLower().Contains("script")) {
  if (!oSession.uriContains("Combinedfilenameorwhatnot")) {
     // Note this flag name is soon changing to X-Format-JS
     oSession["X-FIDDLER-JS-FORMAT"] = "yes";
  }
}

这篇关于有没有办法让Fiddler JS格式化程序扩展有条件地工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 15:48