How to change an object property using the ChromeDevTools?
I ran the following code on nodejs with debugger support:
function test() {
var obj = {
"my_prop": 1
}
return obj; // <- breakpoint here
}
while (true) {
test();
}
Then, I connected with the ChromeDevTools client. Set breakpoint on line 5 (return obj) and received the "Debugger.paused" event, in which I am trying to change the "my_prop" property of the "obj" object using Debugger.setVariableValue like the following code:
var frame = e.CallFrames[0];
var eval = await session.SendAsync(new Debugger.EvaluateOnCallFrameCommand
{
CallFrameId = frame.CallFrameId,
ReturnByValue = false,
Timeout = 10000,
GeneratePreview = true,
IncludeCommandLineAPI = true,
Silent = true,
ThrowOnSideEffect = true,
Expression = "obj"
});
var objectId = eval.Result.Result.ObjectId;
var set = await session.SendAsync(new Debugger.SetVariableValueCommand
{
CallFrameId = frame.CallFrameId,
ScopeNumber = 0,
VariableName = "my_prop",
NewValue = new Runtime.CallArgument
{
ObjectId = objectId,
Value = 900,
UnserializableValue = "900"
},
});
But I get the error '-32603: Internal error'
The local variable is changed successfully using this code
Can anyone tell me where my mistake is?
SOLVED
I missed an important comment: "Object-based scopes are not supported"
I managed to make the necessary assignment through the Debugger.evaluateOnCallFrame:
var eval = await session.SendAsync(new EvaluateOnCallFrameCommand
{
CallFrameId = frame.CallFrameId,
ReturnByValue = true,
Timeout = 10000,
GeneratePreview = true,
IncludeCommandLineAPI = true,
Silent = true,
ThrowOnSideEffect = false, <- must be false
Expression = "obj.my_prop=100"
});
before that, the selected property was true and I got an error when calling this function, so I decided that I should use Debugger.setVariableValue