2014-01-05 2 views
4

Safari 확장을 위해 Chromium의 chrome.webRequest과 같은 것이 있습니까? 나는 그들의 서류 here을 훑어 보았다. 내가 찾을 수있는 가장 가까운 것은 SafariBeforeNavigateEvent입니다. 이렇게하면 새 페이지가로드되지 않지만 서버에 계속 요청을 보냅니다. 또한 AJAX 요청에 따라 리스너를 호출하지 않을 것이라고 생각합니다. 누구나 비슷한 것을 시도 했나요?웹 요청을 차단하는 방법

답변

3

"xmlhttprequest"무시를 사용하여이 문제를 해결했습니다.

이것은 우리의 content.js입니다. (injectedToPage.js)

XMLHttpRequest.prototype.reallySend = XMLHttpRequest.prototype.send; 
XMLHttpRequest.prototype.send = function (body) { 

     console.log("--req.body:---"); 
     console.log(body); 

    this.reallySend(body); 

}; 
var req = new XMLHttpRequest(); 
req.open("GET", "any.html", true); 
req.send(null); 
:

$(document).ready(function() { 

    var myScriptTag = document.createElement('script'); 
    myScriptTag.src = safari.extension.baseURI + 'js/injectedToPage.js'; 
    document.body.appendChild(myScriptTag);  

    });  

코드가 주입 우리는 시작 스크립트로 content.js을 주입