How can I edit javascript in my browser like I can use Firebug to edit CSS/HTML?

前端 未结 5 426
囚心锁ツ
囚心锁ツ 2020-12-04 09:53

Within JSP files, I have some pretty complicated Javascript. On a production machine, we\'re seeing a very weird bug that we have not been able to understand. We have neve

5条回答
  •  既然无缘
    2020-12-04 10:31

    The problem with editing JavaScript like you can CSS and HTML is that there is no clean way to propagate the changes. JavaScript can modify the DOM, send Ajax requests, and dynamically modify existing objects and functions at runtime. So, once you have loaded a page with JavaScript, it might be completely different after the JavaScript has run. The browser would have to keep track of every modification your JavaScript code performs so that when you edit the JS, it rolls back the changes to a clean page.

    But, you can modify JavaScript dynamically a few other ways:

    • JavaScript injections in the URL bar: javascript: alert (1);
    • Via a JavaScript console (there's one built into Firefox, Chrome, and newer versions of IE
    • If you want to modify the JavaScript files as they are served to your browser (i.e. grabbing them in transit and modifying them), then I can't offer much help. I would suggest using a debugging proxy: http://www.fiddler2.com/fiddler2/

    The first two options are great because you can modify any JavaScript variables and functions currently in scope. However, you won't be able to modify the code and run it with a "just-served" page like you can with the third option.

    Other than that, as far as I know, there is no edit-and-run JavaScript editor in the browser. Hope this helps,

提交回复
热议问题