fordcars
fordcars

Reputation: 499

Why am I getting Chrome Native Messaging "Specified native messaging host not found."?

I have been working on this for a while now, I can't figure this out. I've read the Chrome Native Messaging docs, but I keep getting a "Specified native messaging host not found." error from the extension.

Manifest pointed by registry:

{
  "name": "com.fordcars.chromekeys",
  "description": "ChromeKeys description",
  "path": "C:\Users\fordcars\Desktop\Development\ChromeKeys\Debug\ChromeKeys.exe",
    "type": "stdio",
    "allowed_origins": [
     "chrome-extension://pdkakljppghagmaoijbpicogfdbodpbc"
     ]
}

Extension script:

// Event page

var nativeName = "com.fordcars.chromekeys";

var nativePort = chrome.runtime.connectNative(nativeName);

function nativeDataReceived(data)
{
    // Not used
}

function nativeDisconnected()
{
    console.log("Native program disconnected. Error: " + chrome.runtime.lastError.message);
}

nativePort.onMessage.addListener(nativeDataReceived);
nativePort.onDisconnect.addListener(nativeDisconnected);

Keep in mind I get the error as soon as I connectNative(). I have "nativeMessaging" permission in my extension manifest.

Registry:

Subkey: HKEY_CURRENT_USER\Software\Google\Chrome\NativeMessagingHosts\com.fordcars.chromekeys

Value name: (Default)

Value: C:\Users\fordcars\Desktop\Development\ChromeKeys\Debug\nativeManifest.json

Debugging: I have done some debugging and have found that if I change my connectNative nativeName from com.fordcars.chromekeys to anything else, I still get the same error, so it is either not finding the registry key or/and I don't have a good manifest.json.

Thanks!

Upvotes: 1

Views: 3738

Answers (1)

Rob W
Rob W

Reputation: 349032

A backslash is an escape character in JSON. You have to use two backslashes as a path separator in your manifest:

// BAD:
"path": "C:\Users\fordcars\Desktop\Development\ChromeKeys\Debug\ChromeKeys.exe",
// GOOD:
"path": "C:\\Users\\fordcars\\Desktop\\Development\\ChromeKeys\\Debug\\ChromeKeys.exe",

I strongly recommend to learn how to debug as described in Debugging native messaging, because if you do that, then you would have seen a more detailed error message:

Found manifest, but not the binary for native messaging host com.fordcars.chromekeys. Host path specified in the manifest: C:UsersordcarsDesktopDevelopmentChromeKeysDebugChromeKeys.exe

Even without looking at the error log, if you had followed the bullet points at the error message, you could have noticed the difference between the sample manifest and yours (namely the misspelled backslashes).

Upvotes: 2

Related Questions