amazon-kindle-bulk-downloader
amazon-kindle-bulk-downloader copied to clipboard
Failed to parse CRSF token
I am getting the following error:
$ bun run src/index.ts
Getting credentials
Got credentials
Filling username
Filling password
69 | const cookie = (await page.browser().cookies())
70 | .map((c) => c.name + "=" + c.value)
71 | .join(";");
72 | // @ts-expect-error - This is set by the page
73 | const csrfToken = await page.evaluate(() => window.csrfToken);
74 | if (!csrfToken) throw new Error("Failed to get csrfToken");
^
error: Failed to get csrfToken
at <anonymous> (/Users/<mymacusername>/amazon-kindle-bulk-downloader/src/index.ts:74:25)
Bun v1.2.2 (macOS arm64)
error: script "start" exited with code 1
I got this until I deleted my Passkey. It'll prompt you to make a new one the next time you log in.
How do I delete that passkey?
Your Account > Login & Security > Passkey > (garbage can icon)
I've tried that a bunch of times both in Amazon and in my Google Account and no dice. I am still getting the CSRFToken error. :(
Getting credentials
Got credentials
Filling username
Filling password
69 | const cookie = (await page.browser().cookies())
70 | .map((c) => c.name + "=" + c.value)
71 | .join(";");
72 | // @ts-expect-error - This is set by the page
73 | const csrfToken = await page.evaluate(() => window.csrfToken);
74 | if (!csrfToken) throw new Error("Failed to get csrfToken");
^
error: Failed to get csrfToken
I got passed the passkey issue but sadly it says that I have 0 books total out of the actual thousands that I have. I was able to download a book by hand but dont want to go through the exercise of downloading all of my books manually.
$ bun run src/index.ts
Getting credentials
Got credentials
Filling username
Filling password
Got auth
Got device <my crazy device name here>
Found 0 books in total
Did you try bun run start --baseUrl https://www.amazon.com/ ? The baseUrl is necessary.
Did you try
bun run start --baseUrl https://www.amazon.com/? The baseUrl is necessary.
The base url has a default that can be changed. Probably not related.
Try bun run start --baseUrl https://www.amazon.com/ --manualAuth true ... that did it for me.
@laststrawman this did it for me, too. Note: @psotos specifically I ran bun run start --manualAuth --baseUrl "https://www.amazon.com"
Actually exporting the credentials as environment variables (in git bash, 'export OTP=123456') instead of storing them in an .env file did the trick for me.
Did you try
bun run start --baseUrl https://www.amazon.com/? The baseUrl is necessary.
This worked for me. I use amazon.com so I used the url exactly as you had it. I assumed that was the default and I wouldn't need to specify.
If the process doesn't work without specifying, maybe an error should display if it's omitted.
Or if it only works sometimes, perhaps if 0 books are found a note should be displayed underneath: If you believe this result is an error, please make sure you have specified the baseUrl parameter in your command as this is sometimes necessary to retrieve your books.
I also got this CSRF error (amazon.com, macOS). I deleted my passkey and that did not fix the issue. However, adding the --manualAuth flag allowed me to sign in successfully and then the script worked as expected.
In general these CSRF related issues point to the fact that your login did not 100% succeed (for whatever reason). Whilst I am working to improve this — for now, --manualAuth will be your best bet given the tight deadline for amazon stopping support for this feature.
I encountered this because I have not given Amazon my telephone number. Manual login worked great. Thank you!
Having issues with --manualAuth. Puppeteer opens with a captcha to confirm that it isn't bot traffic (they may be on to you) then the following sign in page continuously loads and never progresses once the sign in button is pressed.