How to intercept a web request

前端 未结 1 1980
不思量自难忘°
不思量自难忘° 2020-12-31 21:52

Is there something like Chromium\'s chrome.webRequest for Safari extensions? I went through their documentation here. The closest thing I could find was Safari

相关标签:
1条回答
  • 2020-12-31 22:35

    We solved this problem by using "xmlhttprequest" overriding.

    This is our content.js . We injected content.js as start script

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

    injected code is: (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);
    
    0 讨论(0)
提交回复
热议问题