Debugging Chrome native messaging

折月煮酒 提交于 2020-01-14 02:49:09

问题


I am a beginner in developing Chrome extensions. I am trying to achieve a native messaging between my extension and a C++ code. Here is the C++ code

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;

}

The problem is that the extension does receive any thing and I don't know how to debug the program. I've tried opening Chrome from the terminal so that errors are displayed, but nothing is displayed there. here is the code from the 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");
});

Any way I could debug the program?


回答1:


You can run Chrome with logging enabled and then review the errors using Sawbuck - a handy GUI designed just for that. If the problem is with Chrome, it might shed some light.

see here - http://www.chromium.org/for-testers/enable-logging




回答2:


There are multiple ways to debug but no end-end IDE like debug exists.

  1. to debug your background and content scripts--- background and page content section in chrome tools

  2. to debug the host --- open chrome from terminal with logging enabled

  3. Also native messaging API offers you some methods which will return appropriate error messages like, runtime.lastError

    can refer this



来源:https://stackoverflow.com/questions/21955126/debugging-chrome-native-messaging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!