Undo typing dialog appears often recently, in Safari Recently it started happening on my iPad that a small dialog asking "Undo typing?" appears on a web page in Safari.

The two options offered are Cancel and Undo. No matter which I tap, both make the dialog disappear and nothing else seems to happen.

Why does this dialog appear? What is its purpose?

I run the latest iOS 12.1.1
Go to settings -> general -> accessibility and look for shake to undo. If enabled that box should appear when you shake the device. 

If you don’t want it turn it off.