transitive-bullshit / kindle-ai-export

Export any Kindle book you own as text, PDF, EPUB, or as a custom, AI-narrated audiobook. 🔥
MIT License
46 stars 4 forks source link

Issue: Stuck on Last Page During Screenshot Capture #6

Open helcone opened 2 weeks ago

helcone commented 2 weeks ago

Description:

The program encounters an error when taking screenshots on the last page (Page 248, Index 470) of a Kindle book. Instead of navigating to metadata creation, it becomes stuck, continually taking screenshots. The issue appears related to the inability to properly navigate past the last page.

Details:

Index: 470
Page: 248
Total Pages: 248
Screenshot Path: out/B0CHVWN7QG/pages/470-248.png
Error Message:

unable to navigate to next page; breaking... locator.click: Target page, context or browser has been closed
Call log:
  - waiting for locator('.kr-chevron-container-right')

node:internal/process/esm_loader:48
      internalBinding('errors').triggerUncaughtException(
                                ^

locator.textContent: Target page, context or browser has been closed
    at getPageNav (/home/user/Documents/kindle-ai-export/src/extract-kindle-book.ts:173:8)
    at main (/home/user/Documents/kindle-ai-export/src/extract-kindle-book.ts:258:27)
    at <anonymous> (/home/user/Documents/kindle-ai-export/src/extract-kindle-book.ts:450:1)

Steps to Reproduce:

Run npx tsx src/extract-kindle-book.ts.
It reaches the final page (248 of 248).
Program attempts to navigate further and gets stuck in an infinite screenshot loop.

Expected Behavior: After reaching the last page, the program should proceed to metadata creation and gracefully exit without trying to navigate further.

Potential Cause: The issue may be caused by an unsuccessful attempt to click on a navigation element (.kr-chevron-container-right) on the last page, which might be unavailable or causing a context closure.

I am not really good at coding but this happened on both mac and linux as well I tried to use bith methods headless and with the GUI browser. Tell me how can I help to fix this.

elementT1000 commented 2 days ago

Fixed this by adding an equal sign to the if statement on line 262.


do {
    const pageNav = await getPageNav()
    if (pageNav?.page === undefined) {
      break
    }
    if (pageNav.page >= totalContentPages) {
      break
    }

Added this and some other edits to this fork. Let me know if it works for you :)