欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

使用Fiddle修改在线加载的前端框架js文件,用于各种调试目的 WebIDESAPSAP云平台SAP Cloud Platformweb 

程序员文章站 2022-03-05 15:01:18
...

Sometimes for trouble shooting or research purpose, you would like to make small changes on framework js file, and test how your application would react to those changes. For example I would like to add a new line for debugging purpose before line 70.

 

使用Fiddle修改在线加载的前端框架js文件,用于各种调试目的
            
    
    
        WebIDESAPSAP云平台SAP Cloud Platformweb 

 

It is not possible to make any modifications on the formatted js file done by Chrome “Pretty print” button.

 

使用Fiddle修改在线加载的前端框架js文件,用于各种调试目的
            
    
    
        WebIDESAPSAP云平台SAP Cloud Platformweb 

 

We can only change original unformatted file or switch the source code to debugger version and change Text-dbg.js instead. Unfortunately changes done by both approaches could not be persisted. Once we refresh Chrome, they are gone.

 

使用Fiddle修改在线加载的前端框架js文件,用于各种调试目的
            
    
    
        WebIDESAPSAP云平台SAP Cloud Platformweb 

 

Inspired by Alessandro Spadoni‘s great blog Switch #openui5 version on-the-fly without changing the code – Web Debugging Proxy, now I can use Fiddle to achieve the requirement once and for all:

(1) Download the original Text.js to local laptop. Add the code you would like to insert and save the change.

 

使用Fiddle修改在线加载的前端框架js文件,用于各种调试目的
            
    
    
        WebIDESAPSAP云平台SAP Cloud Platformweb 

 

(2) Open Fiddle, run UI5 application and use Fiddle to capture the network traffic. Find the corresponding session to request Text.js, and drag it to tab “AutoResponder” and drop there. Select the two checkbox “Enable rules” and “Unmatched requests passthrough”.

 

使用Fiddle修改在线加载的前端框架js文件,用于各种调试目的
            
    
    
        WebIDESAPSAP云平台SAP Cloud Platformweb 

 

Once you finished drop, the Text.js url will be automatically populated to Rule Editor.

 

使用Fiddle修改在线加载的前端框架js文件,用于各种调试目的
            
    
    
        WebIDESAPSAP云平台SAP Cloud Platformweb 

 

Select “Find a file” from drop down list and specify the local modified file you have done in previous step.

 

使用Fiddle修改在线加载的前端框架js文件,用于各种调试目的
            
    
    
        WebIDESAPSAP云平台SAP Cloud Platformweb 

 

Once done, you have now created one rule as below: every time the Text.js with given url is accessed, Fiddle will serve it with your local modified version as response.

 

使用Fiddle修改在线加载的前端框架js文件,用于各种调试目的
            
    
    
        WebIDESAPSAP云平台SAP Cloud Platformweb 

 

Now we can re-launch application and have a test. We can observe that this time, the modified Text.js is returned:

 

使用Fiddle修改在线加载的前端框架js文件,用于各种调试目的
            
    
    
        WebIDESAPSAP云平台SAP Cloud Platformweb 

 

And in Chrome development tool, we can also see modified source code of Text.js.

 

使用Fiddle修改在线加载的前端框架js文件,用于各种调试目的
            
    
    
        WebIDESAPSAP云平台SAP Cloud Platformweb 

 

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

使用Fiddle修改在线加载的前端框架js文件,用于各种调试目的
            
    
    
        WebIDESAPSAP云平台SAP Cloud Platformweb