# textSearchInit broken on blank pages

**URL:** <https://pdfjs.community/t/textsearchinit-broken-on-blank-pages/2678>\
**Category:** Bug Reports\
**Tags:** pdfjs-express\
**Created:** [June 29, 2023, 1:41pm UTC](https://pdfjs.community/t/textsearchinit-broken-on-blank-pages/2678 "2023-06-29T13:41:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![axeld](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@axeld](https://pdfjs.community/u/axeld)\
**Post date:** [June 29, 2023, 1:41pm UTC](https://pdfjs.community/t/textsearchinit-broken-on-blank-pages/2678/1 "2023-06-29T13:41:17Z")

</div>

Hello,  
[Document2.pdf](https://pdfjs.community/uploads/short-url/g94H9cPCob7B85ZRLnMFnxlVKbs.pdf) (76.7 KB)

Promise is never resolved if pdf contains a blank page.

On version 8.7.4 the problem is here. It worked well on 8.7.0

```javascript
Core.documentViewer.addEventListener('documentLoaded', async () => {
    await initAnnotate();
});

const initAnnotate = () => {
    console.log('initAnnotate');

    return new Promise(resolve => {
        const searchMode = Core.Search.Mode.REGEX | Core.Search.Mode.HIGHLIGHT | Core.Search.Mode.PAGE_STOP;

        const searchOptions = {
            fullSearch: true, // search the full document,
            onResult: (result) => {
                console.log('onResult');
            },
            onDocumentEnd: () => {
                console.log('onDocumentEnd');
                resolve();
            }
        }

        let searchText = "test";

        Core.documentViewer.textSearchInit(searchText, searchMode, searchOptions);
    });
}

```

---

<div class="post-metadata">

**Author:** ![tgordon](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tgordon](https://pdfjs.community/u/tgordon)\
**Post date:** [June 29, 2023, 11:00pm UTC](https://pdfjs.community/t/textsearchinit-broken-on-blank-pages/2678/3 "2023-06-29T23:00:19Z")

</div>

Hello axeld,

Can you try handling the onError, onResult, and onPageEnd callbacks? There could be an error that is occurring.

Best regards,  
Tyler

---

<div class="post-metadata">

**Author:** ![axeld](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@axeld](https://pdfjs.community/u/axeld)\
**Post date:** [June 30, 2023, 9:11am UTC](https://pdfjs.community/t/textsearchinit-broken-on-blank-pages/2678/4 "2023-06-30T09:11:41Z")

</div>

Hello tgordon,

I already tried to log those callbacks, no errors reported. Plus, 8.7.0 works well.

---

<div class="post-metadata">

**Author:** ![tgordon](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tgordon](https://pdfjs.community/u/tgordon)\
**Post date:** [June 30, 2023, 9:44pm UTC](https://pdfjs.community/t/textsearchinit-broken-on-blank-pages/2678/5 "2023-06-30T21:44:27Z")

</div>

Hi axeld,

Loading the code you provided I see the promise resolve, I modified the resolve to include some text to log. It logs in the console correctly.

```javascript
      const { documentViewer, Annotations } = instance.Core;
      const annotationManager = documentViewer.getAnnotationManager();
      documentViewer.addEventListener('documentLoaded', async () => {
        initAnnotate().then((value)=>{
          console.log(value)
        })
    });
    
    const initAnnotate = () => {
        console.log('initAnnotate');
    
        return new Promise(resolve => {
            const searchMode = instance.Core.Search.Mode.REGEX | instance.Core.Search.Mode.HIGHLIGHT | instance.Core.Search.Mode.PAGE_STOP;
    
            const searchOptions = {
                fullSearch: true, // search the full document,
                onResult: (result) => {
                    console.log('onResult');
                },
                onDocumentEnd: () => {
                    console.log('onDocumentEnd');
                    resolve('documentEnd');
                }
            }
    
            let searchText = "test";
    
            documentViewer.textSearchInit(searchText, searchMode, searchOptions);
        });
    }

```

Best regards,  
Tyler

---

<div class="post-metadata">

**Author:** ![axeld](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@axeld](https://pdfjs.community/u/axeld)\
**Post date:** [July 17, 2023, 1:44pm UTC](https://pdfjs.community/t/textsearchinit-broken-on-blank-pages/2678/6 "2023-07-17T13:44:08Z")

</div>

Ok my bad, I uploaded the wrong document. Can you try with this one ?  
[lastpage.pdf](https://pdfjs.community/uploads/short-url/5wvqzduIWVmpeOGeaZBcsDN0XDK.pdf) (29.0 KB)

I copy/paste your code, and the promise is never resolved. I also tried onError callback, and nothing is logged.

8.7.0 still working with this document, but not 8.7.4.

Thanks.

---

<div class="post-metadata">

**Author:** ![tgordon](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tgordon](https://pdfjs.community/u/tgordon)\
**Post date:** [July 24, 2023, 5:57pm UTC](https://pdfjs.community/t/textsearchinit-broken-on-blank-pages/2678/7 "2023-07-24T17:57:40Z")

</div>

Hello axeld,

I was able to reproduce the issue with the new file provided, I have added this as a bug report to our backlog to be reviewed by our product team. Thank you!

Best regards,  
Tyler

---

<div class="post-metadata">

**Author:** ![axeld](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@axeld](https://pdfjs.community/u/axeld)\
**Post date:** [July 26, 2023, 11:57am UTC](https://pdfjs.community/t/textsearchinit-broken-on-blank-pages/2678/8 "2023-07-26T11:57:57Z")

</div>

Thanks for the answer, have a good day :).
