检测用户在chrome / firefox / safari中查看的网址

时间:2013-06-10 16:20:10

标签: macos cocoa security

如何通过cocoa(桌面应用)检测我在chrome / safari / firefox中浏览的网址?

作为一个侧面但相关的注释,在开发桌面应用程序时是否有任何安全限制,用户将收到警报并询问他们是否允许?例如如果应用访问他们的联系信息等。

寻找基于可可的解决方案,而不是javascript。

5 个答案:

答案 0 :(得分:0)

我会将其作为扩展程序,因为您希望定位Chrome,Safari和Firefox,我会使用像Crossrider这样的跨浏览器扩展框架。

所以去crossrider.com,设置一个帐户并创建一个新的扩展。然后打开background.js文件并粘贴如下代码:

appAPI.ready(function($) {
    appAPI.message.addListener({channel: "notifyPageUrl"}, function(msg) {
        //Do something, like send an xhr post somewhere 
            // notifying you of the pageUrl that the user visited.
        // The url is contained within msg.pageUrl      
    });

    var opts = { listen: true}; 
    // Note: When defining the callback function, the first parameter is an object that
    //       contains the page URL, and the second parameter contains the data passed
    //       to the context of the callback function.
    appAPI.webRequest.onBeforeNavigate.addListener(function(details, opaqueData) {
        // Where:
        //   * details.pageUrl is the URL of the tab requesting the page
        //   * opaqueData is the data passed to the context of the callback function
        if(opaqueData.listen){
            appAPI.message.toBackground({
                msg: details.pageUrl
            }, {channel: "notifyPageUrl"});
        }
    }, opts ); // opts is the opaque parameter that is passed to the callback function
});

然后安装扩展程序!在上面的示例中,没有对用户正在访问的检测到的pageUrl进行任何操作,但您可以在此处执行任何操作 - 您可以向用户发送消息,您可以使用cancel或redirectTo返回参数来限制访问,可以使用crossrider appAPI.db API在本地登录,或者您可以将通知发送到其他地方,跨域,直接从后台直接利用XHR请求。

希望有所帮助!

要回答关于桌面端安全问题的问题,请注意桌面应用程序将拥有运行它们的用户的权限。因此,如果您正在考虑提供一个用户将在本地运行的桌面应用程序,可以通过使用诸如Windows上的winpcap或* nix品种上的libpcap之类的内容来检测他们访问的网址流,然后只需要注意这一点 - 并且libpcap和朋友必须能够访问可以被相关用户置于混杂模式的网卡。

pcap /已安装的桌面应用程序解决方案非常具有侵略性 - 大多数人不希望您真正收听所有内容,实际上可能会违反某些安全策略,具体取决于用户的工作地点 - 他们的网络管理员可能不会感谢您“嗅探” ,这是否是实际目的。安全人员可以就这些主题发表真正的蠢事。

如果我正确理解目标,通过Crossrider进行的扩展可能是实现目标的最简单,最不具侵入性的方式。

最后一点,您可以使用Crossrider的标签API获取所有标签的当前标签页:

// retrieves the array of tabs
appAPI.tabs.getAllTabs(function(allTabInfo) {
    // Display the array
    for (var i=0; i<allTabInfo.length; i++) {
        console.log(
            'tabId: ' + allTabInfo[i].tabId +
            ' tabUrl: ' + allTabInfo[i].tabUrl
        );
    }
});

有关标签API,请参阅:     http://docs.crossrider.com/#!/api/appAPI.tabs

对于后台导航API:     http://docs.crossrider.com/#!/api/appAPI.webRequest.onBeforeNavigate

对于消息:     http://docs.crossrider.com/#!/api/appAPI.message

对于appAPI.db:     http://docs.crossrider.com/#!/api/appAPI.db

答案 1 :(得分:0)

你有没有看过Scripting Bridge?你可以有一个应用程序启动一个Applescript,它可以验证是否有任何一个众所周知的浏览器被打开并询问他们正在查看哪些文档(URL)。

注意:它不一定是苹果;您可以通过cocoa访问Scripting Bridge。

但是,它会要求浏览器支持它。我知道Safari支持它,但如果其他人这样做就会忽略。

答案 2 :(得分:0)

快速说明:

有很多方法可以通过AppleScript完成,您可以轻松地将此代码包装到NSAppleScript调用中。

这是使用适用于Safari和Chrome的AppleScript命令的gist。 Firefox似乎不支持AE。

答案 3 :(得分:-1)

很明显这就是我在谷歌上遇到的。

chrome.tabs。 getSelected (空值, 功能 (标签) { 警报 (tab.url); });

答案 4 :(得分:-2)

在纯JavaScript中我们可以使用

alert(document.URL);

alert(window.location.href)

获取当前网址的功能

相关问题