我是开发 Chrome 扩展的初学者。我正在尝试在我的扩展和 C++ 代码之间实现本机消息传递。这是C++代码
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");
});
有什么办法可以调试程序?