From :
– the relevant extension coding techniques in Mozilla are:
* Use the observer-service to register a « http-on-examine-response » observer.
* When you observe this event, use channel.QueryInterface(Ci.nsIHTTPChannel) to get the HTTP channel from it
* Pull the securityInfo attribute of that channel
* Use QueryInterface(nsISSLStatusProvider) on the securityInfo to access the SSL data from the securityInfo.
* Pull the SSLStatus attribute of the securityInfo
* Use QueryInterface(nsISSLStatus) on the SSLStatus to access the details of the connection. The serverCert attribute contains the server certificate.

CertPatrol contains JavaScript code which does all these steps, as well as much more to parse the certificate and display the chain.
Th source is on-line on addon :
Sample code on MDN:

The getChain() property of nsIX509Cert allows to get the full chain up to the root.

If you are worried you may have been MITM by an intermediate CA, getting to the full chain is very important (it’s perfectly possible for the intermediate CA to generates further intermediate certs that make it very much look like the certificate that directly issued your cert was the correct one, except if you check the complete list).