You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Playwright(Docker)中suggestedFilename获取带重音文件名异常排查

Playwright下载文件时Docker环境下带重音文件名无法正常获取的问题

我使用Playwright下载文件,通过download.suggestedFilename()获取文件名。本地Ubuntu(法语环境)运行正常,但Docker环境中,带重音的文件名会被返回为"download",无重音的文件名则能正常获取。

核心代码

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)

环境输出对比

  • 本地Ubuntu(法语环境)输出:
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
  • Docker环境输出:
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

已尝试的解决操作

我推测问题与Content-Disposition响应头及区域设置有关,已在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

# Create 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

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm ci
RUN npx playwright install --with-deps chrome

# Move app src
COPY src/. src/.
COPY tsconfig.json ./.
# Buld app
RUN npm run build

# Copy docker bashs cripts
COPY docker/job.sh .
RUN chmod +x ./job.sh

COPY docker/entrypoint.sh .
RUN chmod +x ./entrypoint.sh

# Create the log file to be able to run tail
RUN touch /var/log/cron.log
CMD [ "./entrypoint.sh" ]

请问有什么解决思路?

注:我正在基于一个Google Photos备份项目进行二次开发。


内容的提问来源于stack exchange,提问作者prigal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 13:17:03