user2403876
user2403876

Reputation: 339

Running external programs from Chrome apps

So I've been wrestling with this one for half the night and haven't found any clear-cut answers on Google or SO, so please excuse me for potentially asking a duplicate question. :)

So I've been researching how to run native apps from a Google Chrome app, and while I think I've reached about 75% of what is needed, I still have more questions than answers. I've read all the documentation on "native messaging", including the debugging part, but there just doesn't seem to be enough documentation yet (I'm guessing Chrome apps are still a new concept, which is why most of Google's docs are for extensions). Anyway here's some code:

chrome.app.window.create('index.html', {
    id: 'main',  // Tried replacing this with the app ID found in chrome://extensions; still didn't work.
    bounds: { width: 200, height: 500 }
});

    // Looks simple enough, I'll explain the randomness later :)
    chrome.runtime.sendNativeMessage("test1", { text: "whatever" });

});

I registered my native app as a "host" and that worked fine. Here's what that looked like:

REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\test1" /ve /t REG_SZ /d "C:\\My 

Stuff\Code\Projects\Desktop\MyProject\source\native.json" /f And here's the file at that location:

{
    "name": "native_app",
    "description": "A native app (in this case an AutoHotkey script)",
    "path": "native.exe",
    "type": "stdio",
    "allowed_origins": [
        "chrome-extension://gielahlojnnpjhamfiebdcppafijhppb"
    ]
}

The end result:

TypeError: chrome.runtime.sendNativeMessage is not a function

So, now I'm down to the questions:

  1. I've seen that "not a function" error for my own code and usually know how to fix it; but since this is point to Google's API...???? Obviously, Google defined it someplace, or it wouldn't be in their docs; so what else could cause it to cough up this error? The closest I could find on SO was from someone trying to send a native message from a content script in an extension (unrelated). So debugging this goober's gonna be fuuuuun... :/ lol idk

  2. I noticed under "allowed_origins" it says "extension" - should I replace that with "app" since it's a Chrome app? The documentation doesn't say.

  3. Are the chrome.* APIs for Chrome apps and extensions the same? Most of what I've done with extensions is content scripts, so I don't really know for sure, but they seem to be awful similar so maybe? That would explain why most of the docs and posts out there are for extensions only (but then it wouldn't matter if it was for an extension or app).

And I've got a ton of others, but this is enough for one post, lol. Thanks! :)

Upvotes: 0

Views: 228

Answers (1)

user2403876
user2403876

Reputation: 339

Sorry to answer my own question (well #1 anyway): The problem was the permissions in my manifest file. It was "not a function" because I didn't add that part. But now it's returning undefined (and response text is undefined) so I still got way too much research to do (and it's like 4 AM, lol). So questions 2 & 3 are still open. Thanks again.

Upvotes: 1

Related Questions