Ruuhkis
Ruuhkis

Reputation: 1934

Google Chrome editing Javascript on the fly

I've tried to ease my life by using Google Chrome's devtools and as I've tried to modify javascript of page on fly but it seems to behave unexpectedly

I have this function that is called every frame of the game

View.prototype.onHit = function() {
    for(var i = 0; i < this.obstacles.length; i++) {
        if(this.obstacles[i].dealsDamage) {
            //deal damage
        } else {
            //do something else
        }
    }
}

and when I open it on chromes "Sources tab" and pause execution and add something simple such as

console.log("hey");

it starts printing text "hey" on console as expected but the moment i modify some code such as the if check to

        if(!this.obstacles[i].dealsDamage) {
            //do something else
        } else {
            //deal damage
        }

inverting the behaviour and save the document, the code doesnt take effect and the logging source changes to View.js (old)

and anything I change after that doesn't affect the running javascript

Screenshot from console

Upvotes: 0

Views: 2284

Answers (1)

beefeather
beefeather

Reputation: 1040

The "(old)" script normally should only appear if the more complex changes are applied. Namely, if you change a function parameter number or start (and lamently stop) using a variable from outer scope.

If live edit fails to work in such simple use-case as you describe, it could be a good thing to file to http://crbug.com

Upvotes: 2

Related Questions