首页 > 解决方案 > 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();

标签: javascriptjquerygoogle-chrome-extension

解决方案


那么你需要使用request.fetch,

您可以用下面的代码替换您的代码

fetch(kima[0].src,{cache : "force-cache"}).then(r => r.blob({type: 'image/jpg'})).then(blob => function_to_catch_blob(blob));

希望这可以帮助你!


推荐阅读