简体   繁体   中英

Edit JavaScript code in chrome and reload page

Very often I hack and play with the JavaScript code on some website. Many times JavaScript code is secured in a function:

(function(){
    var = ...
    ...
}());

and I cannot access the object defined in that scope.

Moreover such code is only executed once, when the page loads, thus modifying it with the chromium/google-chrome developer console (Sources toool) is useless.

Is there any simple way to live-edit some JavaScript code in a page and reload the page so that it runs the modified code?

Have a look at using something like Tampermonkey https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=en

the Chrome equivalent of Firefox's Greasemonkey

EDIT: you could use this in combination with adblock to disable the loading of the script you are targeting: https://stackoverflow.com/questions/13919183/how-to-turn-off-one-javascript-or-disable-it-under-chrome

我不会称之为简单 ,但像Intercept Proxy这样的东西可能会这样做 - 用另一个文件替换一个文件。

I found a way to achieve what I needed.

Using Chromium's debugger I can set a breakpoint on any statement of the source code.

Once that statement is executed, the code suspends and Chromium's console gives me access to whatever is in the stack of the current function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM