Trying to use Playwright to download a file and set the filename using download.suggestedFilename().
Code snippet:
const downloadPromise = page.waitForEvent('download', {timeout:100000})
await page.keyboard.down('Shift')
await page.keyboard.press('KeyD')
const download = await downloadPromise
const tempPath = await download.path()
console.log(' - tempPath : ' +tempPath)
const suggestedFilename = await download.suggestedFilename()
console.log(' - suggestedFilename : ' +suggestedFilename)
Output on local machine (ubuntu, French) with npx tsx:
23/01/2024 22:04:20 ( 8.78) : - tempPath : /tmp/playwright-artifacts-zUHKYv/ab49a46d-cdcb-46fb-bd5a-8695661713e3
23/01/2024 22:04:20 ( 8.78) : - suggestedFilename : Congrès 24.jpg
Output on docker for the same URL:
23/01/2024 21:35:48 ( 13.90) : - tempPath : /tmp/playwright-artifacts-qCYQZ2/713b56eb-6d85-474a-b40e-68fc28da088e
23/01/2024 21:35:48 ( 13.90) : - suggestedFilename : download
Issue seems related to Content-Disposition header and locale, as files without accents work while those with accents are named "download".
Tried adding lines to Dockerfile:
RUN apt-get install -y locales locales-all
ENV LC_ALL fr_FR.UTF-8
ENV LANG fr_FR.UTF-8
ENV LANGUAGE fr_FR.UTF-8
Dockerfile:
FROM mcr.microsoft.com/playwright
# App directory
WORKDIR /usr/src/app
RUN apt-get update && apt-get -y install cron
RUN apt-get install -y locales locales-all
ENV LC_ALL fr_FR.UTF-8
ENV LANG fr_FR.UTF-8
ENV LANGUAGE fr_FR.UTF-8
COPY package*.json ./
RUN npm ci
RUN npx playwright install --with-deps chrome
COPY src/. src/.
COPY tsconfig.json ./.
RUN npm run build
COPY docker/job.sh .
RUN chmod +x ./job.sh
COPY docker/entrypoint.sh .
RUN chmod +x ./entrypoint.sh
RUN touch /var/log/cron.log
CMD [ "./entrypoint.sh" ]
Any suggestions? NB: working on fork of https://github.com/CasperVerswijvelt/google-photos-backup