Debugging Chrome native messaging

2019-05-19 06:24发布

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?

2条回答
看我几分像从前
2楼-- · 2019-05-19 06:31

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

查看更多
该账号已被封号
3楼-- · 2019-05-19 06:31

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

查看更多
登录 后发表回答