How to get all nodes? ( as listed in the scene explorer)

I want to implement a undo/ redo function, my idea is to save all nodes (their positions) in a variable before an event and after it. But how can I get them?
( see the scene explorer on the left, the nodes are all listed there)

One way is to use the scene.rootNodes property to get all the root nodes and recursively get all the children nodes. Not all nodes will have positions, so you’ll have to check for that.