javascript - Google Chrome 扩展 - 从缓存中获取图像
问题描述
我正在重新编程一个 Google Chrome 扩展程序,它能够使用src属性下载图像,但是现在,页面改变了它显示图像的方式,它在src属性中使用了某种在后台更改图像的脚本,获取网页显示的不同图像。我可以看到我需要的图像,但使用 NIRSOFT 的“ChromeCacheView”,但它是桌面解决方案,因此无法在 Chrome 扩展程序中执行此操作。
有人可以帮助我,拜托!
下面的代码是我现在正在使用的代码,但正如我已经说过的,它无法向我显示正在显示的网页图像。
var xhr = new XMLHttpRequest();
// I think here is where I need the change Getting this ID from cache
var kima = $(frame1).contents().find("#ccontrol1");
xhr.open('GET',kima[0].src,true);
//
xhr.responseType = 'blob';
xhr.onload = function(e) {
if (this.status == 200) {
var blob = new Blob([this.response], {type: 'image/png'});
kym_send_image(blob);
kym_process01();
}
};
xhr.onerror = function (e) {
window.location.href = url1;
return;
};
xhr.send();
解决方案
那么你需要使用request.fetch,
您可以用下面的代码替换您的代码
fetch(kima[0].src,{cache : "force-cache"}).then(r => r.blob({type: 'image/jpg'})).then(blob => function_to_catch_blob(blob));
希望这可以帮助你!
推荐阅读
- mysql - 选择具有相应时间的 MAX(列值)的行,按名称区分
- ios - textField shouldChangeCharactersInRange 函数 Swift5
- angular - 错误类型错误:无法读取 ab.address.city 未定义的属性“城市”
- console - 如何删除 Emily:跳过原因已经从控制台日志运行日志?
- azure - 我可以为同一个 Web 作业的 2 个实例设置单独的 settings.job
- html - 为什么我的文本中没有显示 HTML 链接
- python - 我可以使用 YouTube Analytics API 找到我的 YouTube 频道的展示次数吗
- javascript - 如何将表单数据保存到文本文件?
- neo4j - 密码命令未被识别
- java - 如何在 Java 中通过 Selenium webdriver 选择 href 元素?