2012-09-28 47 views

回答

0

你試過details.responseHeaders[i].name = 'text/plain; charset=utf-8';

+0

名稱中包含我試圖操縱他們兩個沒有運氣 – user1031143

2

只是沒有

chrome.webRequest.onHeadersReceived.addListener(function (details) { 
    var yeniheaderlar = 
     [{ 
      name : "Content-Security-Policy", 
      value : "sil" 
     }, { 
      name : "Content-Security-Policy-Report-Only", 
      value : "sil" 
     }, { 
      name : "X-Content-Security-Policy", 
      value : "sil" 
     }, { 
      name : "X-WebKit-CSP", 
      value : "sil" 
     }, { 
      name : "X-Frame-Options", 
      value : "sil" 
     }, { 
      name : "X-XSS-Protection", 
      value : "sil" 
     }, { 
      name : "Access-Control-Allow-Origin", 
      value : "*" 
     }, { 
      name : "Access-Control-Allow-Methods", 
      value : "POST, GET, OPTIONS, DELETE, PUT" 
     }, { 
      name : "Access-Control-Allow-Headers", 
      value : "*" 
     } 
    ]; 
    for (z = 0; z < yeniheaderlar.length; z++) { 
     var zamazingo = false; 
     for (i = 0; i < details.responseHeaders.length; i++) { 
      if (details.responseHeaders[i].name.toLowerCase() == yeniheaderlar[z].name.toLowerCase()) { 
       if (yeniheaderlar[z].value == "sil") { 
        details.responseHeaders.splice(i, 1); 
       } else { 
        details.responseHeaders[i].value = yeniheaderlar[z].value; ; 
       } 
       zamazingo = true; 
      } 
     } 
     if (!zamazingo && (yeniheaderlar[z].value != 'sil')) { 
      details.responseHeaders.push(yeniheaderlar[z]); 
     } 
    } 
    return { 
     responseHeaders : details.responseHeaders 
    }; 
}, { 
    urls : ["<all_urls>"], 
    types : ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"] 
}, 
    ["blocking", "responseHeaders"]); 
+0

頭的頭,價值=價值的名字在這個答案的關鍵是'「堵」'(最後一個參數) 。 **使用**這個值,Chrome會在繼續處理請求之前等待您的函數返回。 –