chrome.webRequest对于Safari扩展,有没有类似Chromium的东西?我在这里查看了他们的文档.我能找到的最接近的是SafariBeforeNavigateEvent.这将阻止新页面加载,但仍会将请求发送到服务器.此外,我认为它不会在AJAX请求上调用侦听器.有人试过类似的东西?
小智 6
我们通过使用"xmlhttprequest"覆盖来解决这个问题.
这是我们的content.js.我们将content.js注入了启动脚本
$(document).ready(function() {
var myScriptTag = document.createElement('script');
myScriptTag.src = safari.extension.baseURI + 'js/injectedToPage.js';
document.body.appendChild(myScriptTag);
});
Run Code Online (Sandbox Code Playgroud)
注入的代码是:(injectToPage.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);
Run Code Online (Sandbox Code Playgroud)