Get entered document password

Q: How can I capture the password entered by the user when opening a document?

You will need to add an event listener to change events on the password input DOM element rendered by PSPDFKit when a document is password-protected and an input is needed.

Since the PSPDFKit.Instance reference doesn’t resolve until a password is used and the document finally opened, you can rely on a MutationObserver to act upon the rendering of the main PSPDFKit iframe and then add another one to capture a reference to the password input presented. All of this before the call to PSPDFKit.load.

let passwordEntered = "";

const config = {
childList: true,
subtree: true

const observer = new MutationObserver((_, observer) => {
const mainIframe = defaultConfiguration.container.querySelector(
if (mainIframe) {
    const innerObserver = new MutationObserver((_, observer) => {
    const passwordInput = mainIframe.contentDocument.querySelector(
    if (passwordInput) {
        passwordInput.addEventListener("change", e => {
        passwordEntered =;
    innerObserver.observe(mainIframe.contentDocument, config);


observer.observe(defaultConfiguration.container, config);


This has been tested with PSPDFKit for Web 2021.2.0.