Uncaught (in promise) TypeError: Cannot read property 'setCustomModal' of undefined

Uncaught (in promise) TypeError: Cannot read property 'setCustomModal' of undefined

我是 Javascript 的新手,我正在学习一些关于使用 PDFTron 显示 pdf 的教程。但是我在设置自定义属性时遇到问题。你能告诉我我在哪里犯了错误吗?

 window.webviewerFunctions = {
      initWebViewer: function () {
          const viewerElement = document.getElementById('viewer');
          WebViewer({
              path: 'lib',
              initialDoc: 'lib/simpledoc.pdf', // replace with your own PDF file
          }, viewerElement)
          .then((instance) => {
              instance.setTheme('dark');
              instance.disableElements(['downloadButton','printButton' ]);
              instance.disableElements(['toolbarGroup-Insert']);
             
              
          })
          .then(function(instance) {
            var modal = {
              dataElement: 'meanwhileInFinlandModal',
              render: function renderCustomModal(){
                var div = document.createElement("div");
                div.style.color = 'white';
                div.style.backgroundColor = 'hotpink';
                div.style.padding = '20px 40px';
                div.style.borderRadius = '5px';
                div.innerText = 'Meanwhile in Finland';
                return div
              }
            }
            instance.setCustomModal(modal);
            instance.openElements([modal.dataElement]);
            });
      }
    };

Promise 处理程序需要 return instance 因为这是作为输入传递给链中下一个处理程序的内容。

   .then((instance) => {
              instance.setTheme('dark');
              instance.disableElements(['downloadButton','printButton' ]);
              instance.disableElements(['toolbarGroup-Insert']);
              return instance;
          })