Google chrome extension Chrome/FF/Safari扩展:以类似匿名模式加载隐藏网页

Google chrome extension Chrome/FF/Safari扩展:以类似匿名模式加载隐藏网页,google-chrome-extension,firefox-addon,sandbox,safari-extension,incognito-mode,Google Chrome Extension,Firefox Addon,Sandbox,Safari Extension,Incognito Mode,是否可以构建“匿名模式”以在浏览器扩展中加载背景网页? 我正在编写一个非IE跨浏览器扩展,它代表用户定期检查网页。有两个要求: 页面检查在后台进行,尽可能不引人注目。我相信这可以通过在新的无焦点浏览器选项卡中打开页面,或者隐藏在扩展的背景页面的沙盒iframe中来实现 页面检查应在“匿名模式”下运行,且不得使用/更新用户的cookie、历史记录或本地存储。这是为了尽可能地阻止检查污染用户的实际浏览行为 关于如何实施这种“隐姓埋名模式”有什么想法吗? 理想情况下,它可以在尽可能多的浏览器类型中工作

是否可以构建“匿名模式”以在浏览器扩展中加载背景网页?

我正在编写一个非IE跨浏览器扩展,它代表用户定期检查网页。有两个要求:

  • 页面检查在后台进行,尽可能不引人注目。我相信这可以通过在新的无焦点浏览器选项卡中打开页面,或者隐藏在扩展的背景页面的沙盒iframe中来实现
  • 页面检查应在“匿名模式”下运行,且不得使用/更新用户的cookie、历史记录或本地存储。这是为了尽可能地阻止检查污染用户的实际浏览行为
  • 关于如何实施这种“隐姓埋名模式”有什么想法吗?

    理想情况下,它可以在尽可能多的浏览器类型中工作(而不是IE)

    我目前的想法是:

    • 从与页面检查相关联的传入/传出http请求中筛选出cookie头(如果我可以识别所有这些请求的话)(在Safari中不可能?)
    • 在每个页面检查之后,从用户的历史记录中筛选出该页面
    我发现了一些有用的问题:

    必须保留对我们添加的iframe的全局var引用。 然后,您可以像这样更改iframe位置,当它被加载时,它会触发上面的事件侦听器

    iframe.contentWindow.location = 'http://www.bing.com/'
    
    DOMContentLoaded标识在该iframe中加载的所有内容。如果页面有帧,它也会检测到

    要从历史记录中删除,请在DOMContentLoaded函数中使用历史记录服务从历史记录中删除win.location:

    现在,要从该页面中的请求中删除cookie,请使用以下代码:

    const {classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu, results: Cr, manager: Cm} = Components;
    Cu.import('resource://gre/modules/Services.jsm');
    
    var myTabToSpoofIn = Services.wm.getMostRecentBrowser('navigator:browser').gBrowser.tabContainer[0]; //will spoof in the first tab of your browser
    
    var httpRequestObserver = {
        observe: function (subject, topic, data) {
            var httpChannel, requestURL;
    
            if (topic == "http-on-modify-request") {
                httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
                var goodies = loadContextGoodies(httpChannel)
                if (goodies) {
                  if (goodies.contentWindow.top == iframe.contentWindow.top) {
                    httpChannel.setRequestHeader('Cookie', '', false);
                  } else {
                    //this page load isnt in our iframe so ignore it
                  }
                }
            }
        }
    };
    
    Services.obs.addObserver(httpRequestObserver, "http-on-modify-request", false);
    //Services.obs.removeObserver(httpRequestObserver, "http-on-modify-request", false); //run this on shudown of your addon otherwise the observer stags registerd
    
    
    
    
    
    
    
    //this function gets the contentWindow and other good stuff from loadContext of httpChannel
    function loadContextGoodies(httpChannel) {
        //httpChannel must be the subject of http-on-modify-request QI'ed to nsiHTTPChannel as is done on line 8 "httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);"
        //start loadContext stuff
        var loadContext;
        try {
            var interfaceRequestor = httpChannel.notificationCallbacks.QueryInterface(Ci.nsIInterfaceRequestor);
            //var DOMWindow = interfaceRequestor.getInterface(Components.interfaces.nsIDOMWindow); //not to be done anymore because: https://developer.mozilla.org/en-US/docs/Updating_extensions_for_Firefox_3.5#Getting_a_load_context_from_a_request //instead do the loadContext stuff below
            try {
                loadContext = interfaceRequestor.getInterface(Ci.nsILoadContext);
            } catch (ex) {
                try {
                    loadContext = subject.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext);
                } catch (ex2) {}
            }
        } catch (ex0) {}
    
    if (!loadContext) {
        //no load context so dont do anything although you can run this, which is your old code
        //this probably means that its loading an ajax call or like a google ad thing
        return null;
    } else {
        var contentWindow = loadContext.associatedWindow;
        if (!contentWindow) {
            //this channel does not have a window, its probably loading a resource
            //this probably means that its loading an ajax call or like a google ad thing
            return null;
        } else {
            var aDOMWindow = contentWindow.top.QueryInterface(Ci.nsIInterfaceRequestor)
                .getInterface(Ci.nsIWebNavigation)
                .QueryInterface(Ci.nsIDocShellTreeItem)
                .rootTreeItem
                .QueryInterface(Ci.nsIInterfaceRequestor)
                .getInterface(Ci.nsIDOMWindow);
            var gBrowser = aDOMWindow.gBrowser;
            var aTab = gBrowser._getTabForContentWindow(contentWindow.top); //this is the clickable tab xul element, the one found in the tab strip of the firefox window, aTab.linkedBrowser is same as browser var above //can stylize tab like aTab.style.backgroundColor = 'blue'; //can stylize the tab like aTab.style.fontColor = 'red';
            var browser = aTab.linkedBrowser; //this is the browser within the tab //this is where the example in the previous section ends
            return {
                aDOMWindow: aDOMWindow,
                gBrowser: gBrowser,
                aTab: aTab,
                browser: browser,
                contentWindow: contentWindow
            };
        }
    }
    //end loadContext stuff
    

    }

    要执行与从历史记录中删除相反的操作,您可以这样添加到历史记录中:
    var historyService2=Components.classes[“@mozilla.org/browser/nav history service;1”].getService(Components.interfaces.nsIGlobalHistory2);historyService2.addURI(Services.io.newURI('http://www.bing.com/'),假、真、空)什么在详细的回应!三件事:1)你能修改代码格式吗?有些地方似乎不见了。2) Cookie还需要从http响应中删除。我想我们可以创建一个“httpResponseObserver”,它可以监听“http on examine response”?3) “myTabToSpoofIn”变量用于任何事情吗?啊,不,我在事故中留下了
    myTabToSpoofIn
    ,它来自我发布的另一个示例。您只需要保持对iframe的全局引用。是的,正在进行cookie剥离。请参见固定格式,它在那里,
    httpChannel.setRequestHeader('cookie','',false)谢谢!答案被接受。我仍在开发Firefox扩展,但您的信息看起来非常有用。目前正在开发Chrome版本。
    
    const {classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu, results: Cr, manager: Cm} = Components;
    Cu.import('resource://gre/modules/Services.jsm');
    
    var myTabToSpoofIn = Services.wm.getMostRecentBrowser('navigator:browser').gBrowser.tabContainer[0]; //will spoof in the first tab of your browser
    
    var httpRequestObserver = {
        observe: function (subject, topic, data) {
            var httpChannel, requestURL;
    
            if (topic == "http-on-modify-request") {
                httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
                var goodies = loadContextGoodies(httpChannel)
                if (goodies) {
                  if (goodies.contentWindow.top == iframe.contentWindow.top) {
                    httpChannel.setRequestHeader('Cookie', '', false);
                  } else {
                    //this page load isnt in our iframe so ignore it
                  }
                }
            }
        }
    };
    
    Services.obs.addObserver(httpRequestObserver, "http-on-modify-request", false);
    //Services.obs.removeObserver(httpRequestObserver, "http-on-modify-request", false); //run this on shudown of your addon otherwise the observer stags registerd
    
    
    
    
    
    
    
    //this function gets the contentWindow and other good stuff from loadContext of httpChannel
    function loadContextGoodies(httpChannel) {
        //httpChannel must be the subject of http-on-modify-request QI'ed to nsiHTTPChannel as is done on line 8 "httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);"
        //start loadContext stuff
        var loadContext;
        try {
            var interfaceRequestor = httpChannel.notificationCallbacks.QueryInterface(Ci.nsIInterfaceRequestor);
            //var DOMWindow = interfaceRequestor.getInterface(Components.interfaces.nsIDOMWindow); //not to be done anymore because: https://developer.mozilla.org/en-US/docs/Updating_extensions_for_Firefox_3.5#Getting_a_load_context_from_a_request //instead do the loadContext stuff below
            try {
                loadContext = interfaceRequestor.getInterface(Ci.nsILoadContext);
            } catch (ex) {
                try {
                    loadContext = subject.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext);
                } catch (ex2) {}
            }
        } catch (ex0) {}
    
    if (!loadContext) {
        //no load context so dont do anything although you can run this, which is your old code
        //this probably means that its loading an ajax call or like a google ad thing
        return null;
    } else {
        var contentWindow = loadContext.associatedWindow;
        if (!contentWindow) {
            //this channel does not have a window, its probably loading a resource
            //this probably means that its loading an ajax call or like a google ad thing
            return null;
        } else {
            var aDOMWindow = contentWindow.top.QueryInterface(Ci.nsIInterfaceRequestor)
                .getInterface(Ci.nsIWebNavigation)
                .QueryInterface(Ci.nsIDocShellTreeItem)
                .rootTreeItem
                .QueryInterface(Ci.nsIInterfaceRequestor)
                .getInterface(Ci.nsIDOMWindow);
            var gBrowser = aDOMWindow.gBrowser;
            var aTab = gBrowser._getTabForContentWindow(contentWindow.top); //this is the clickable tab xul element, the one found in the tab strip of the firefox window, aTab.linkedBrowser is same as browser var above //can stylize tab like aTab.style.backgroundColor = 'blue'; //can stylize the tab like aTab.style.fontColor = 'red';
            var browser = aTab.linkedBrowser; //this is the browser within the tab //this is where the example in the previous section ends
            return {
                aDOMWindow: aDOMWindow,
                gBrowser: gBrowser,
                aTab: aTab,
                browser: browser,
                contentWindow: contentWindow
            };
        }
    }
    //end loadContext stuff