Pdf js viewer throwing error on Firefox

PDF.js Express Version

Detailed description of issue
Hi ,
On loading the viewer on firefox we are getting an error msg on loading

Expected behaviour
Pls find attached screenshot

Does your issue happen with every document, or just one?
Happens with every pdf. I am using this version of pdfjs : ^7.0.1
@pdftron/pdfjs-express”: “^7.0.1”,
@pdftron/pdfjs-express-utils”: “^1.2.3”,

Link to document
{Provide a link to the document in question if possible}

Code snippet
wvDocumentLoadedHandler(): void {
// you can access docViewer object for low-level APIs
const docViewer = this.wvInstance;
const annotManager = this.wvInstance.annotManager;
//and access classes defined in the WebViewer iframe
const { Annotations } = this.wvInstance;
this.wvInstance.closeElements([‘loadingModal’]);
}
getDataById(info, id, index) {
this.selectIndex = index;
this.pdf_url = info
this.fileId = id
this.wvInstance.openElements([‘loadingModal’]);
// here info is the S3 url of pdf
this.wvInstance.docViewer.loadDocument(info)

}

Hey there!

This looks like it would be an issue with your code and not PDF.js Express.

Could you provide some code showing how you are loading Express and where this.wvInstance is getting set?

Thanks,
Logan

Thanks Logan !

Please find the attached code to load the Webviewer instance.

wvInstance;
  ngOnInit() {
    this.wvDocumentLoadedHandler = this.wvDocumentLoadedHandler.bind(this);
  
    this.detailsStepService.hasSubmittalId.subscribe(res => {
      this.submittalId = res;
    });
  }


  wvDocumentLoadedHandler(): void {
    const docViewer = this.wvInstance;
    const annotManager = this.wvInstance.annotManager;
    const { Annotations } = this.wvInstance;
    this.wvInstance.closeElements(['loadingModal']);
  }
  getDataById(info, id, index, instance?:any) {
    console.log('instance 2', instance);
    this.wvInstance = instance;
    this.selectIndex = index;
    console.log(info)
    this.pdf_url = info
    this.fileId = id
    console.log(this.fileId)
    this.wvInstance.openElements(['loadingModal']);
    this.wvInstance.docViewer.loadDocument(info)
    if (this.files.length > 1 && index != 0) {
      console.log('files greater than 1');
      this.sendForOCr();
    }
  }
  async ngAfterViewInit(): Promise<void> {
    WebViewer({
      licenseKey: 'u4Utg1NNWOrQZIX32Rxu',
      disableFlattenedAnnotations: true,
      path: '../../wv-resources/lib',
      config: '../../wv-resources/lib/ui/config/file.js', // relative to your HTML file
      disabledElements: [
        'selectToolButton', 'toolbarGroup-Edit', 'toolsHeader', 'searchButton', 'header',
        'panToolButton', 'toggleNotesButton', 'notesPanel', 'menuButton', 'highlightToolGroupButton', 'underlineToolGroupButton', 'strikeoutToolGroupButton', 'stickyToolGroupButton', 'freeHandToolGroupButton',
        'toolsOverlay', 'viewControlsButton', 'leftPanelButton', 'toolbarGroup-Insert', 'toolbarGroup-Shapes', 'squigglyToolGroupButton', 'freeTextToolGroupButton',
      ],
     
    }, this.viewer.nativeElement).then(instance => {
      console.log('instance 1', instance);
      this.wvInstance = instance;
    
      const tempSubmittalId = this.route.snapshot.queryParams['submittal'];
      if (tempSubmittalId) {
        this.submittalId = tempSubmittalId;
        this.detailsStepService.changeSubmittalId(tempSubmittalId);
        this.initiatePDFeditor(instance);
      }

      const utils = new ExpressUtils({
        serverKey: '49EzA6YczS1pfUG7ZYZy',
        clientKey: '0U7UA9kWPkFSfX3iQNB5'
      })

      const { Annotations, Tools, annotManager, docViewer } = instance;
      // set pdf to full width of viewer
      instance.setFitMode(instance.FitMode.FitWidth);
)}
}

  initiatePDFeditor(instance?:any) {
    this.fileUploadService.getDataById(this.submittalId).subscribe(res => {
      this.files = res;

      for (let file of this.files) {
        file["active"] = false;
      }

      if (this.files.length > 0) {
        this.getDataById(this.files[0].file_info, this.files[0].id, 0, instance);
      }
    }, err => {
      const error = err.error || 'Server Error';
      this.openSnackBar(error);
    });
  }

Hey there!

Are you by chance setting display: none to the viewer element? Firefox has a weird bug where setting display: none makes iframe’s behave weirdly, which breaks the viewer.

Hey Logan ,
No we are not using setting display :none to it. Its weird because the viewer gets loaded if we refresh the browser but does not load the first time.

Hi,

It sounds like its probably some kind of timing issue, possibly caused by how/when you are loading WebViewer.

I would suggest adding some logs and breakpoints throughout your code to check for timing issues. Make sure that WebViewer is finished loading before trying to use this.wvInstance.

Also, if you are using some kind of Tab or Navigation library, it may be setting elements to display:none without you directly knowing it. You could make sure this is not the case either.

I do not believe this issue is being caused directly by PDF.js Express.

Let me know your findings!

Thanks,
Logan