Textbox2 unexpectedly reset its text in the center in PsychJS (fine in PsychoPy)

That is very strange. I reduced the overhead (I think) by using the following code:

if textbox.contains(mouse):
    if textbox.color != "red":
        textbox.color = "red"
        textbox.borderColor = "red"
else:
    if textbox.color == "red":
        textbox.color = "black"
        textbox.borderColor = "black"

With my version of your cod the text flicks to the centre for one frame while the text colour is being changed. It looks like you can’t type on the same frame as a colour change. In your code the colour is being set every frame.