2014-02-22 57 views
1

我是開發Chrome擴展的初學者。我試圖在我的擴展和C++代碼之間實現本地消息傳遞。這裏是C++代碼調試Chrome本機消息

int main(int argc, char* argv[]) { 
// Define our message 
char message[] = "{\"text\": \"This is a response message\"}"; 
// Collect the length of the message 
unsigned int len = strlen(message); 
// We need to send the 4 bytes of length information 
printf("%c%c%c%c", (char) (len & 0xff), 
        (char) ((len>>8) & 0xFF), 
        (char) ((len>>16) & 0xFF), 
        (char) ((len>>24) & 0xFF)); 
// Now we can output our message 
printf("%s", message); 
return 0; 

}

的問題是該分機所不接受任何事情,我不知道如何來調試程序。我已經嘗試從終端打開Chrome,以便顯示錯誤,但沒有任何顯示。這裏是從background.js代碼

var port = chrome.runtime.connectNative('com.my_company.my_application'); 

port.onMessage.addListener(function(msg) { 
    console.log("Received" + msg); 
}); 

port.onDisconnect.addListener(function() { 
    console.log("Disconnected"); 
}); 

任何方式,我可以調試程序?

+0

查看http://stackoverflow.com/questions/18134665/how-to-send-message-from-native-app-to-chrome-extension/19866346 – vaughan

回答

0

有多種方式來調試,但沒有端到端的IDE像調試存在。

  1. 調試你的背景和內容腳本---在Chrome工具

  2. 背景和頁面內容部分調試主機---開放Chrome與記錄終端啓用

  3. 本地消息傳遞API還爲您提供一些方法,可以返回相應的錯誤消息,如runtime.lastError

    can refer this