How to handle NTLM authentication

Prev Next

This page explains how to handle testing on websites that use NTLM (New Technology LAN Manager) authentication.

Configuration (Playwright Code Step)

To handle NTLM authentication, add a Playwright code step to the beginning of your scenario to configure the automatic provision of credentials via the Chrome DevTools Protocol (CDP).

Please add the following code as a Playwright code step:

const username = "username"
const password = "password"

const cdp = await context.newCDPSession(page)

cdp.on("Fetch.requestPaused", ({ requestId }) =>
  cdp.send("Fetch.continueRequest", { requestId })
)
cdp.on("Fetch.authRequired", ({ requestId }) => {
  cdp.send("Fetch.continueWithAuth", {
    requestId,
    authChallengeResponse: {
      response: "ProvideCredentials",
      username,
      password
    }
  })
})
await cdp.send("Fetch.enable", { handleAuthRequests: true })

Please replace username and password on the first and second lines of the code with the actual username and password specified by the customer.

Notes and Limitations

If the username contains a backslash () (e.g., DOMAIN\user), it must be escaped in the code by writing \\ (two backslashes).

(Example: const username = "DOMAIN\\user" )

  • Credential Scope: The username and password set in this code step will be automatically used for all NTLM authentication prompts that occur during this scenario execution.