fix: support location-based books and handle updated Kindle Cloud Reader UI - #23
Open
emwbae wants to merge 1 commit into
Open
Conversation
…der UI
parsePageNav() correctly returns { location, total } for books displaying
"Location X of Y", but the main extraction loop only checked pageNav.page,
causing an immediate break on the first iteration — resulting in 0 captured
pages for any location-based book.
Additionally, Amazon's Kindle Cloud Reader UI renamed "Go to Page" to
"Go to Location" and changed several element selectors, causing goToPage()
to timeout and crash the entire extraction process.
|
Fyi, as of writing this this branch still works, the main one does not. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two bugs that prevent extraction from working on a significant number of Kindle books:
Location-based books produce 0 pages —
parsePageNav()inplaywright-utils.tsalready handles the"Location X of Y"footer format, correctly returning{ location, total }. However, the main extraction loop inextract-kindle-book.tsonly checkspageNav?.page, which isundefinedfor location-based books. This triggers thebreakon the very first iteration, producing an empty result with 0 captured pages.goToPage()crashes on current Kindle Cloud Reader — Amazon renamed the menu item from "Go to Page" to "Go to Location" and changed the underlying element structure. The hardcoded selectors (ion-item[role="listitem"]withhasText: 'Go to Page',input[placeholder="page number"],ion-button[item-i-d="go-to-modal-go-button"]) all fail to match, causing a timeout that kills the extraction before any pages are captured.Changes
Location-based book support (main extraction loop)
const currentPage = pageNav?.page ?? pageNav?.locationto fall back to location when page number is undefinedtotalNumContentPagesbounds check to only apply whenpageNav.pageis defined — location-based books don't have a meaningful page-to-content-page mapping, so the originalpageNav.page > totalNumContentPagescheck would never fire anyway (it was thepageNav?.page === undefinedcheck above it that caused the early exit)screenshotPath,pageChunk, assertion messages) to usecurrentPageinstead ofpageNav.pageResilient
goToPage()navigation.or()fallbacks for bothion-buttonand plainbuttonelements'Go to Page'string to regex/go to (location|page)/ito handle both old and new Kindle Cloud Reader UIplaceholder*="page"andplaceholder*="location")item-i-dattribute)goToPage(initialPageNav.page)reset in try/catch to prevent a crash after all pages have already been successfully capturedReproduction
npx tsx src/extract-kindle-book.tsparsePageNav()returns{ location: X, total: Y }(no.pageproperty), and the loop immediately breaks onpageNav?.page === undefinedRelated issues
goToPage()call prevents the "target page closed" crash that occurs when the browser context is closingKnown limitations
The downstream export scripts (
export-book-markdown.ts,export-book-pdf.ts,export-book-audio.ts) usetocItem.pageandcontent.findIndex((c) => c.page >= nextTocItem.page!)to map chapters to content chunks. For location-based books, thePageChunk.pagefield now contains location numbers rather than page numbers, which may cause chapter boundary mismatches in exports. This is a pre-existing limitation (these scripts couldn't work at all before since extraction produced 0 pages) and would be best addressed in a follow-up PR.Validated
goToPage()gracefully recovers when selectors don't match (Escape key dismisses modals)prettierandeslint(pre-commit hooks ran successfully)