Repository: mozilla/pdf.js
File: web/pdf_link_service.js (JavaScript)

Code before:
        pageNumber > 0 &&
        pageNumber <= this.pagesCount
      )
    ) {
      console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
      return;
    }

    if (this.pdfHistory) {
      // Update the browser history before scrolling the new page into view,
      // to be able to accurately capture the current document position.
      this.pdfHistory.pushCurrentPosition();
      this.pdfHistory.pushPage(pageNumber);
    }

    this.pdfViewer.scrollPageIntoView({ pageNumber });
  }

  /**
   * Scrolls to a specific location in the PDF document.
   * @param {number} pageNumber - The page number to scroll to.
   * @param {number} x - The x-coordinate to scroll to in page coordinates.
   * @param {number} y - The y-coordinate to scroll to in page coordinates.
   */
  goToXY(pageNumber, x, y) {
    if (this.pdfDocument) {
      this.pdfViewer.scrollPageIntoView({
        pageNumber,
        destArray: [null, { name: "XYZ" }, x, y],
        ignoreDestinationZoom: true,
      });
    }
  }

  /**
   * Adds various attributes (href, title, target, rel) to hyperlinks.
   * @param {HTMLAnchorElement} link
   * @param {string} url
   * @param {boolean} [newWindow]
   */
  addLinkAttributes(link, url, newWindow = false) {
    if (!url || typeof url !== "string") {
      throw new Error('A valid "url" parameter must provided.');
    }
    const target = newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
      rel = this.externalLinkRel;

    if (this.externalLinkEnabled) {
      link.href = link.title = url;
    } else {
      link.href = "";

Review comment (suggestion):
This `if` statement is not necessary because `scrollPageIntoView` already checks this internally; see https://github.com/mozilla/pdf.js/blob/ab41f5095cfb25a67ba55cc085e7dde92d85cc65/web/pdf_viewer.js#L1567-L1569.

Code after:
        pageNumber > 0 &&
        pageNumber <= this.pagesCount
      )
    ) {
      console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
      return;
    }

    if (this.pdfHistory) {
      // Update the browser history before scrolling the new page into view,
      // to be able to accurately capture the current document position.
      this.pdfHistory.pushCurrentPosition();
      this.pdfHistory.pushPage(pageNumber);
    }

    this.pdfViewer.scrollPageIntoView({ pageNumber });
  }

  /**
   * Scrolls to a specific location in the PDF document.
   * @param {number} pageNumber - The page number to scroll to.
   * @param {number} x - The x-coordinate to scroll to in page coordinates.
   * @param {number} y - The y-coordinate to scroll to in page coordinates.
   */
  goToXY(pageNumber, x, y) {
    this.pdfViewer.scrollPageIntoView({
      pageNumber,
      destArray: [null, { name: "XYZ" }, x, y],
      ignoreDestinationZoom: true,
    });
  }

  /**
   * Adds various attributes (href, title, target, rel) to hyperlinks.
   * @param {HTMLAnchorElement} link
   * @param {string} url
   * @param {boolean} [newWindow]
   */
  addLinkAttributes(link, url, newWindow = false) {
    if (!url || typeof url !== "string") {
      throw new Error('A valid "url" parameter must provided.');
    }
    const target = newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
      rel = this.externalLinkRel;

    if (this.externalLinkEnabled) {
      link.href = link.title = url;
    } else {
      link.href = "";
      link.title = `Disabled: ${url}`;
      link.onclick = () => false;