webRequest.getSecurityInfo()

Use this function to get detailed information about the TLS connection associated with a particular request.

You pass this function the requestId for the request in question, and some optional extra parameters. It returns a Promise which will resolve to a SecurityInfo object.

You can only call this function from inside the webRequest.onHeadersReceived listener. The requestId can be found in the details object which is passed into the listener.

You must also pass the "blocking" option to webRequest.onHeadersReceived.addListener(). So to use this API you must have the "webRequestBlocking" API permission, as well as the normal permissions needed for using webRequest listeners (the "webRequest" permission and the host permission for the host).

Syntax

js
let gettingInfo = browser.webRequest.getSecurityInfo(
  requestId,       // string
  options          // optional object
)

Parameters

requestId

string. ID of the request for which you want security info. You can get this from the details object that is passed into any webRequest event listeners.

options Optional

object. An object that can contain any of these properties:

certificateChain Optional

boolean. If true, the SecurityInfo object returned will include the entire certificate chain up to and including the trust root. If false, it will include only the server certificate. Defaults to false.

rawDER Optional

boolean. If true, every CertificateInfo in the SecurityInfo.certificates property will contain a property rawDER. This contains the DER-encoded ASN.1 that comprises the certificate data.

Return value

A Promise which resolves to a SecurityInfo object.

Examples

This example listens for all HTTPS requests to "mozilla.org" or its subdomains, and logs the subject name in the server certificate:

js
async function logSubject(details) {
  try {
    let securityInfo = await browser.webRequest.getSecurityInfo(
      details.requestId,
      {},
    );
    console.log(details.url);
    if (securityInfo.state === "secure" || securityInfo.state === "weak") {
      console.log(securityInfo.certificates[0].subject);
    }
  } catch (error) {
    console.error(error);
  }
}

browser.webRequest.onHeadersReceived.addListener(
  logSubject,
  { urls: ["https://*.mozilla.org/*"] },
  ["blocking"],
);

This example listens for all HTTPS requests to "mozilla.org" or its subdomains, and logs the name in the trusted root certificate:

js
async function logRoot(details) {
  try {
    let securityInfo = await browser.webRequest.getSecurityInfo(
      details.requestId,
      { certificateChain: true },
    );
    console.log(details.url);
    if (securityInfo.state === "secure" || securityInfo.state === "weak") {
      console.log(
        securityInfo.certificates[securityInfo.certificates.length - 1].issuer,
      );
    }
  } catch (error) {
    console.error(error);
  }
}

browser.webRequest.onHeadersReceived.addListener(
  logRoot,
  { urls: ["https://*.mozilla.org/*"] },
  ["blocking"],
);

Example extensions

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
getSecurityInfo
Chrome – No support
Chrome
footnote
footnote See bug 41264310
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 62 (Release date: 2018-09-05)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – Full support
Firefox for Android 62 (Release date: 2018-09-05)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
options
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – No support
Firefox 62 – 129 (Release date: 2018-09-05)
footnote Required
Firefox – Full support
Firefox 130 (Release date: 2024-09-03)
footnote
footnote Optional
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android 62 – 129 (Release date: 2018-09-05)
footnote Required
Firefox for Android – Full support
Firefox for Android 130 (Release date: 2024-09-03)
footnote
footnote Optional
Safari on iOS – No support
Safari on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.
Has more compatibility info.