Getting a self-signed certificate error when trying to install the Chromium module in Python
Within VS Code, I installed Playwright successfully using pip install playwright. Now AI told me that I needed to install Chromium, but the command playwright install chromium didn't work within my VS Code terminal window because it didn't recognize the playwright command.

So AI again told me to run the command python -m playwright install chromium instead, wherein I received an "Error: self-signed certificated in certificate chain". The full stack is shown below here.
PS C:\Code> python -m playwright install chromium
Downloading Chrome for Testing 149.0.7827.55 (playwright chromium v1228) from https://cdn.playwright.dev/builds/cft/149.0.7827.55/win64/chrome-win64.zip
Error: self-signed certificate in certificate chain
at TLSSocket.onConnectSecure (node:internal/tls/wrap:1742:34)
at TLSSocket.emit (node:events:509:28)
at TLSSocket._finishInit (node:internal/tls/wrap:1179:8)
at ssl.onhandshakedone (node:internal/tls/wrap:965:12) {
code: 'SELF_SIGNED_CERT_IN_CHAIN'
}
Downloading Chrome for Testing 149.0.7827.55 (playwright chromium v1228) from https://cdn.playwright.dev/builds/cft/149.0.7827.55/win64/chrome-win64.zip
Error: self-signed certificate in certificate chain
at TLSSocket.onConnectSecure (node:internal/tls/wrap:1742:34)
at TLSSocket.emit (node:events:509:28)
at TLSSocket._finishInit (node:internal/tls/wrap:1179:8)
at ssl.onhandshakedone (node:internal/tls/wrap:965:12) {
code: 'SELF_SIGNED_CERT_IN_CHAIN'
}
Downloading Chrome for Testing 149.0.7827.55 (playwright chromium v1228) from https://cdn.playwright.dev/builds/cft/149.0.7827.55/win64/chrome-win64.zip
Error: self-signed certificate in certificate chain
at TLSSocket.onConnectSecure (node:internal/tls/wrap:1742:34)
at TLSSocket.emit (node:events:509:28)
at TLSSocket._finishInit (node:internal/tls/wrap:1179:8)
at ssl.onhandshakedone (node:internal/tls/wrap:965:12) {
code: 'SELF_SIGNED_CERT_IN_CHAIN'
}
Downloading Chrome for Testing 149.0.7827.55 (playwright chromium v1228) from https://cdn.playwright.dev/builds/cft/149.0.7827.55/win64/chrome-win64.zip
Error: self-signed certificate in certificate chain
at TLSSocket.onConnectSecure (node:internal/tls/wrap:1742:34)
at TLSSocket.emit (node:events:509:28)
at TLSSocket._finishInit (node:internal/tls/wrap:1179:8)
at ssl.onhandshakedone (node:internal/tls/wrap:965:12) {
code: 'SELF_SIGNED_CERT_IN_CHAIN'
}
Downloading Chrome for Testing 149.0.7827.55 (playwright chromium v1228) from https://cdn.playwright.dev/builds/cft/149.0.7827.55/win64/chrome-win64.zip
Error: self-signed certificate in certificate chain
at TLSSocket.onConnectSecure (node:internal/tls/wrap:1742:34)
at TLSSocket.emit (node:events:509:28)
at TLSSocket._finishInit (node:internal/tls/wrap:1179:8)
at ssl.onhandshakedone (node:internal/tls/wrap:965:12) {
code: 'SELF_SIGNED_CERT_IN_CHAIN'
}
Failed to install browsers
Error: Failed to download Chrome for Testing 149.0.7827.55 (playwright chromium v1228), caused by
Error: Download failure, code=1
at ChildProcess. (C:\Users\ahmed\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\playwright\driver\package\lib\coreBundle.js:27793:32)
at ChildProcess.emit (node:events:509:28)
at ChildProcess._handle.onexit (node:internal/child_process:295:12)It seems the solution is to run the command $env:NODE_TLS_REJECT_UNAUTHORIZED='0'; python -m playwright install chromium which apparently worked.
PS C:\Code> $env:NODE_TLS_REJECT_UNAUTHORIZED='0'; python -m playwright install chromium
Downloading Chrome for Testing 149.0.7827.55 (playwright chromium v1228) from https://cdn.playwright.dev/builds/cft/149.0.7827.55/win64/chrome-win64.zip
(node:37008) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
(Use node --trace-warnings ... to show where the warning was created)
183.6 MiB [================ ] 79% 5.4s