Live Javascript edit in Safari?

2019-04-19 01:32发布

问题:

In Chrome this is possible, but I don't find a way to do it in Safari. Is it possible? How?

回答1:

Currently this is not possible.



回答2:

The closest option is to pause JavaScript and execute commands from the console.

To open Safari dev tools, press CtrlAltC on Windows or commandoptionC Mac. Or enable Safari dev commands in the menubar in Safari Preferences -> Advanced -> Show Develop Menu.

See Apple's docs on how to use its dev tools.

Unlike in Chrome, the Safari debugger does not currently support the ability to click on a script file and edit it in place. However, you can still stop execution using break points or the pause button, then execute code in the console to alter values, then resume execution.

For example, if you have the code:

var t = 1;
(function(){
    var t = 2;
    console.log(t);  //* put break point on this line..    
})();
console.log(t);

And you but a break point where indicated, then run t = 4 in the console, the value 4 then 1 are printed to the console.



回答3:

Although both chrome and safari use webkit as their engine, chrome makes its own customizations and additions over it. Live editing of javascript seems to be one of them.

If you look closely the debugging panels in chrome and safari have many other differences as well. A clearly visible change is settings icon present in chrome and thats not available in safari.