如何在Chrome中更改响应标题 [英] how to change response header in Chrome
问题描述
我正在处理互联网上的一些mp3链接。
当使用Chrome开发者工具时,我看到一些响应标头包含 是否有任何允许更改响应标题的Chrome扩展程序?因为我想改变Content-Type 请参阅 下面是一个简单的例子,它修改了 请注意,您必须声明 I'm dealing with some mp3 link on the internet. When using Chrome developer tool, I see some have response header with Are there any Chrome extensions that allow changing response header? Because I want to change Content-Type See the Chrome developer page. Here's a simple example that modifies Note that you have to declare both 这篇关于如何在Chrome中更改响应标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! Content-Type:application / octet-stream
(像这样的链接迫使Chrome下载),一些链接具有
Content-Type
https://www.google.com/
改为text / plain。
chrome.webRequest.onHeadersReceived.addListener(details => {
let header = details.responseHeaders.find(e => e.name .toLowerCase()==='content-type');
header.value ='text / plain';
return {responseHeaders:details.responseHeaders};
},{urls: ['https://www.google.com/']},['blocking','responseHeaders']);
webRequest
和 webRequestBlocking
权限 manifest.json
。Content-Type:application/octet-stream
(links like these force Chrome to download), some links have reponse header with Content-Type:audio/mpeg
(links like these allow Chrome to play them streamingly).Content-Type
of https://www.google.com/
to text/plain.chrome.webRequest.onHeadersReceived.addListener(details => {
let header = details.responseHeaders.find(e => e.name.toLowerCase() === 'content-type') ;
header.value = 'text/plain';
return {responseHeaders: details.responseHeaders};
}, {urls: ['https://www.google.com/']}, ['blocking', 'responseHeaders']);
webRequest
and webRequestBlocking
permissions in manifest.json
.