@@ -5,7 +5,8 @@ import path from 'node:path'
55
66import { input } from '@inquirer/prompts'
77import delay from 'delay'
8- import { chromium , type Locator } from 'playwright'
8+ // import { chromium, type Locator } from 'playwright'
9+ import { chromium , type Locator } from 'patchright'
910
1011import type { BookInfo , BookMeta , BookMetadata , PageChunk } from './types'
1112import {
@@ -34,6 +35,7 @@ async function main() {
3435 assert ( asin , 'ASIN is required' )
3536 assert ( amazonEmail , 'AMAZON_EMAIL is required' )
3637 assert ( amazonPassword , 'AMAZON_PASSWORD is required' )
38+ const asinL = asin . toLowerCase ( )
3739
3840 const outDir = path . join ( 'out' , asin )
3941 const userDataDir = path . join ( outDir , 'data' )
@@ -44,18 +46,31 @@ async function main() {
4446 const krRendererMainImageSelector = '#kr-renderer .kg-full-page-img img'
4547 const bookReaderUrl = `https://read.amazon.com/?asin=${ asin } `
4648
49+ // const context = await chromium.launchPersistentContext(userDataDir, {
50+ // headless: false,
51+ // channel: 'chrome',
52+ // executablePath:
53+ // '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
54+ // args: ['--hide-crash-restore-bubble'],
55+ // ignoreDefaultArgs: ['--enable-automation'],
56+ // deviceScaleFactor: 2,
57+ // viewport: { width: 1280, height: 720 }
58+ // })
59+
4760 const context = await chromium . launchPersistentContext ( userDataDir , {
4861 headless : false ,
4962 channel : 'chrome' ,
50- executablePath :
51- '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' ,
52- args : [ '--hide-crash-restore-bubble' ] ,
63+ args : [
64+ '--hide-crash-restore-bubble' ,
65+ '--disable-features=PasswordAutosave' ,
66+ '--disable-features=WebAuthn'
67+ ] ,
5368 ignoreDefaultArgs : [ '--enable-automation' ] ,
5469 deviceScaleFactor : 2 ,
5570 viewport : { width : 1280 , height : 720 }
5671 } )
57- const page = await context . newPage ( )
5872
73+ const page = context . pages ( ) [ 0 ] ?? ( await context . newPage ( ) )
5974 let info : BookInfo | undefined
6075 let meta : BookMeta | undefined
6176
@@ -68,7 +83,7 @@ async function main() {
6883 if (
6984 url . hostname === 'read.amazon.com' &&
7085 url . pathname === '/service/mobile/reader/startReading' &&
71- url . searchParams . get ( 'asin' ) ?. toLowerCase ( ) === asin . toLowerCase ( )
86+ url . searchParams . get ( 'asin' ) ?. toLowerCase ( ) === asinL
7287 ) {
7388 const body : any = await response . json ( )
7489 delete body . karamelToken
0 commit comments