You need to enable JavaScript to run this app. Chrome中chrome.downloads.download的filename及MIME参数失效
优惠活动
大模型
产品
解决方案
定价
更多

Chrome中chrome.downloads.download的filename及MIME参数失效

我编写了一个可通过URL下载文件的JS函数,但在Chrome环境下运行时无法显示正确的文件名。看起来filename变量没有成功传递给chrome.downloads.download方法,同时自定义的MIME类型也无法正常生效。我添加了alert语句验证变量值,alert可以正常输出正确的filename,请问有人知道这是什么原因导致的吗?
谢谢。

function downloadDownloader(context) {
    const filename = `download-${tabInfo.carNumber}.sh`;
    const bash = (downloaderType === 'hls' ? bashTemplate4hls : bashTemplate).compile(context);
    const blob = new Blob([bash], {
        type: 'text/x-shellscript'
    });
    const url = URL.createObjectURL(blob);
    alert(filename);
    chrome.downloads.download({
        url,
        saveAs: true,
        filename
    });
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.11.27 18:06:03