禁用缓存Chrome扩展程序 [英] Disable cache Chrome Extension

查看:145
本文介绍了禁用缓存Chrome扩展程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个插件,可以加载游戏网站的少数页面,但是我希望它在加载时也禁用缓存.我只能找到在重新加载期间禁用缓存.我可以加载页面,然后每次都重新加载,但这似乎并不理想.有什么方法可以通过选项卡本身甚至是域来禁用生成的选项卡的缓存.

I made a plugin that loads a handful of pages of my game website, but I'd like it to also disable the cache as it loads. I can only find cache disabling during reloading. I could load the page, then reload it every time, but that seems not ideal. Is there some way I could disable the cache for my generated tabs, either by the tabs themselves or even the domain.

推荐答案

wOxxOm说的是正确的,使用webRequest API可以修改缓存控制标头.我需要为此制作背景脚本:

What wOxxOm said is correct, using the webRequest API I could modify the cache-control headers. I needed to make a background script with this:

chrome.webRequest.onBeforeSendHeaders.addListener(
function (details) {
    var headers = details.requestHeaders || [];
    headers.push({
        "name": "Cache-Control",
        "value": "no-cache"
    });
    return {requestHeaders: headers};
},
{
    urls: [
        "*://test.domain.tv/*",
        "*://domain.tv/*"
    ]
},
[]
);

我还必须在清单中添加"webRequest".

I also had to add "webRequest" to my manifest.

这篇关于禁用缓存Chrome扩展程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆