This is handy, but you can very easily do this automatically with fiddler. It automatically swaps out all of the certs though.
In that case you can add its key to a trusted authorities in Firefox and then it swaps nothing, everything seems to be signed properly... Unless I misunderstood your comment.
The substituted public key allows the proxy to negotiate a TLS session between the browser and the proxy, impersonating the real server.
You avoid a certificate error if you install the signing CA certificate in the browser; but you still tamper with the traffic. There are scenarios where mitm doesn't work; for example Client Authenticated TLS. Things like certificate pinning, where the browser expects a specific public key, also break intetception.