通过chrome扩展将数据从winforms传输到chrome

时间:2014-08-08 10:07:05

标签: winforms google-chrome

我在c#中有一个Windows应用程序,其中我通过chrome扩展程序获取以chrome打开的页面的Html 这就是我写一个chrome扩展

的方法

background.js

chrome.tabs.onUpdated.addListener(function(tabId,changeInfo,tab){

if (changeInfo.status === 'complete') {
    chrome.tabs.executeScript(tabId, { file: "jquery.min.js" }, function () {
        chrome.tabs.executeScript(tabId, { file: "content.js" }, function () {
            chrome.tabs.sendMessage(tabId, { text: tab }, function (data) {
                alert("hi");
                chrome.tabs.getAllInWindow(data.WindowId, function (response) {                        
                    for (var i = 0; i < response.length; i++) {
                        if ((response[i].index + 1) == data.Tab) {
                            chrome.tabs.update(response[i].id, { selected: true });
                        }
                    }
                });
            });
        });
    });
}

});

Content.js

chrome.runtime.onMessage.addListener(function(msg,sender,sendResponse){

$.post(listener, { dom: document.all[0].outerHTML }, function (data) {

});

});

现在我需要通过winform按钮将一些数据发送到chrome。请帮忙。

1 个答案:

答案 0 :(得分:0)

知道了,我们可以使用本机消息传递应用程序通过本机应用程序消息传递与chrome进行交互

  

https://developer.chrome.com/extensions/messaging#native-messaging