Observe document editor visibility

Q: I need to get notified when document editor gets displayed or hidden.

A: You can use the viewState.change event listener to check whether or not the Document Editor is being displayed:

//Add the event listener to the instance
  instance.addEventListener("viewState.change", (viewState, previousState) => {
    //check if the current view state is "document_editor"
    if (viewState.interactionMode?.toLowerCase() === "document_editor") {
      console.log("Document Editor Displaying");
    //Otherwise if the previous view state is "document_editor" the document editor was closed
    if (previousState.interactionMode?.toLowerCase() === "document_editor") {
      console.log("Document Editor Hidden");

This has been tested with PSPDFKit for Web 2020.6.4.