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

如何用JavaScript在Chrome控制台无弹窗下载当前页面图片

Chrome控制台无干扰下载指定图片的方法

你可以在Chrome控制台中执行以下代码,实现不打开新标签、不改变当前窗口、不影响页面状态的图片下载:

async function downloadImage(url, filename) {
  const response = await fetch(url);
  const blob = await response.blob();
  const urlObj = URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = urlObj;
  a.download = filename || 'Main-Game-Screen.webp';
  a.style.display = 'none';
  document.body.appendChild(a);
  a.click();
  document.body.removeChild(a);
  URL.revokeObjectURL(urlObj);
}

// 调用函数,可自定义文件名
downloadImage('https://static.monstermmorpg.com/images/HowToPlayTheGame/Main-Game-Screen.webp', '游戏主界面.webp');

代码说明:

  • 通过fetch请求图片资源并转换为Blob对象
  • 创建隐藏的<a>标签,利用download属性指定保存的文件名
  • 触发点击后立即移除标签并释放临时URL,避免内存占用
  • 整个过程在后台执行,不会对当前页面产生任何可见影响

内容的提问来源于stack exchange,提问作者Furkan Gözükara

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 05:59:55