how to change response header in Chrome

前端 未结 1 762
南方客
南方客 2020-12-14 05:04

I\'m dealing with some mp3 link on the internet.

When using Chrome developer tool, I see some have response header with Content-Type:application/octet-stream<

相关标签:
1条回答
  • 2020-12-14 05:52

    See the Chrome developer page.

    Here's a simple example that modifies 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']);
    

    Note that you have to declare both webRequest and webRequestBlocking permissions in manifest.json.

    0 讨论(0)
提交回复
热议问题