Using Google Chrome to debug and edit javascript embedded in HTML page

前端 未结 5 1284
终归单人心
终归单人心 2021-01-31 07:00

Chrome developer tools allows you to edit javascript in the browser if the javascript is in a .js file. However, it does not seem to allow me to edit javascript that is embedded

5条回答
  •  失恋的感觉
    2021-01-31 07:51

    None of these answers have worked for me.

    What works for me is if I have my javascript on the page already loaded, I can copy that javascript, edit it, then paste it in the console and it will redefine any functions or whatever that I need to be redefined.

    for instance, if the page has:

    
    

    I can take the content between the script, edit it, then enter it into the debugger like:

    foo = function() { console.log("DO SOMETHING DIFFERENT"); }
    

    and it will work for me.

    Or if you have like,

    function foo() {
        doAThing();
    }
    

    You can just enter

    function foo() {
        doSomethingElse();
    }
    

    and foo will be redefined.

    Probably not the best workaround, but it works.

提交回复
热议问题