Porting Extension from Chrome : macOS Native Messaging

  • Hello,

    I'm trying to port my Chrome extension to Opera. It uses Native Messaging to communicate with my native Macintosh (macOS) application. It's not working in Opera.

    The line of JavaScript code which is supposed to open a port,
    port = chrome.runtime.connectNative(hostName);
    executes successfully (without raising) in a try{} block, and returns what appears to be a port object, but my messaging tool does not launch.

    In looking at that documentation, I find it strange that my I am told to install my special manifest file here:
    /Library/Google/Chrome/NativeMessagingHosts/com.my_company.my_application.json
    First of all, this is, eeeek, in the Google/Chrome subdirectory, which seems like the wrong company :)) Second, because this path does not begin with a tilde (~) it is, eeeek, in a system-admin level directory. Because of this, I had to enter my administrator password twice in order to create the folder and put it there. Google Chrome gives you the option to put it in the user's directory instead, which I do for my Chrome extension.

    Is this just a copy and paste error from the Chrome documentation? If so, what is the correct location for the special manifest .json file?
    Has anyone ever tested or used an Opera extension with Native Messaging on a Macintosh?

    Thanks!

  • I tried to putting my special manifest file in a more logical location,

    ~/Library/Application Support/com.operasoftware.OperaDeveloper/NativeMessagingHosts

    But still my messaging tool does not launch.

    I've also looked through the Opera Add-Ons for another extension which I thought might be using Native Messaging but could not find any. I imagine that they would need to be associated with a native app that would install the manifest and messaging tool, like my extension.

    Has anyone ever used Native Messaging in an Opera Extension? I wonder if this feature has ever been tested?

    Thank you!

  • I agree, it is broken. It was broken, I filed a bug report. DNA-23526, They fixed it.
    Then it broke again sometime, at least for extensions in developer mode, same extension works in Chromium, it doesn't in Opera. Mostly on error ***Can't find manifest for native messaging host com.my_company.my_application, while it's there. I field another bug report, but no fix DNA-43909. Since then I use Chromium a bit more. 😉

    To debug

    • start Opera from terminal, it will give you some errors in terminal.
    • Try the official example.
      Strangely that one works in Opera, while my own do not work in Opera, but they do work in Chromium.

    Path to manifest (I use it in opera-developer).

    • On Linux: ~/.config/opera-developer/NativeMessagingHosts/com.my_company.my_application.json
    • On OSX (I guess): ~/Library/Application Support/Opera/NativeMessagingHosts/com.my_company.my_application.json
    • for chromium: ~/.config/chromium/NativeMessagingHosts/com.my_company.my_application.json

    Annoyingly, there is no error message, when you have set the extension ID wrong

    "allowed_origins": [ "chrome-extension://xxx/" ]

  • Yes, Opera uses the path for Google Chrome to look for manifests:

    ~/.config/google-chrome/NativeMessagingHosts

    Now I know why the example works, I had it also installed in Google Chrome, not my own extensions. When I place the manifest in above Google Chrome location the extension starts working.

    Will file another bug report, pfff.

  • janghou, thank you very much for sharing your experience. I've been trying your various suggestions, but no success so far. Please clarify: when you got the example to work, were on running Linux or Apple macOS?

  • After trying everything, I too have filed a new bug with the Opera Bug Wizard. The Opera Bug Wizard did not give me a Bug Number. All I got was this:

    DNAWIZ-3797.

    The remainder of this post is the text of my bug report.


    Summary

    I have developed browser extensions for many years, including one for Google Chrome, which uses their Native Messaging API. Even though Vivaldi does not provide any documentation, it works in Vivaldi the same as it does in Chrome, with obvious changes. I was able to install my extension and get it working in Vivaldi in less than an hour. But I cannot get it to work in Opera, and after trying every reasonable variation on the ambiguities in the documentation, I have concluded that the Native Messaging API does not work in Opera when running in mac OS (OS X). I am using Opera version 38.

    Details

    When my extension runs in Opera, the line of JavaScript code which is supposed to open a port,

    port = chrome.runtime.connectNative(hostName);
    

    executes successfully (without raising) in a try{} block, and returns what appears to be a port object, but its properties are rather empty, and my native binary does not launch, as it does when my extension runs in Google Chrome or Vivaldi.

    In looking at that documentation, I find it strange that my I am told to install my Native Messaging manifest file here:

    • /Library/Google/Chrome/NativeMessagingHosts/com.mycompany.myapplication.json

    First of all, the Google/Chrome subdirectory is owned by, you know, the wrong browser company. Second, because this path does not begin with a tilde (~) it is, eeeek, in a system-admin level directory. Because of this, I had to enter my administrator password twice in order to create the folder and put it there. Google Chrome gives you the option to put it in the user's directory instead, which I do for my Chrome extension.

    I also tried putting my Native Messaging manifest file in other reasonable locations:

    • ~/Library/Google/Chrome/NativeMessagingHosts/
    • ~/Library/Application Support/com.operasoftware.Opera/NativeMessagingHosts/
    • ~/Library/Application Support/Opera/NativeMessagingHosts/

    but none of these worked either.

    In addition to the Google/Chrome path mentioned above, there are other indications that this documentation was never thoroughly reviewed and tested, for example,

    Chrome starts the host in a separate process…

    Obviously, this should have been changed to:

    Opera starts the host in a separate process…

    To resolve this issue, Opera staff should please review the documentation and make corrections as necessary so that they can make a simple example extension which works, and post a link to it in the documentation. Maybe I'm making some silly mistake, but, you know for something like this, with multiple moving parts, a working example is essential.

    Thank you for reading.

    Jerry Krinock

  • I agree, the documentation seems to be copied, and not updated. I can't imagine the path for a manifest should be a google path instead of it's own .config/opera path, although I agree that is reality, but I consider this a bug.

    What happens when you install your extensions, I can get them working using the Google Chrome path for the manifest.

  • Hi!

    Big thanks for such a detailed investigation on this topic.

    I'm really sorry to hear this bug as well as errors in the documentation prevent you from writing great extensions for Opera.

    Now the big report is going to be reviewed by our QA team.

  • @kszularz thx, maybe this can help, the bugs I filed on this issue:

    • DNA-23526
    • DNA-43909
    • DNAWIZ-3730
  • @kszularz: Thank you, and please read on.

    @janghour: Sorry I didn't quite understand your first posts. As I said earlier, my extension did not launch its native messaging tool when I installed a Native Messaging manifest file in the /Library/Google/Chrome… system directory as specified in the documentation, nor when I installed it in any reasonable Opera directory. However, just now I added the ID of the extension installed in Opera to the allowed_origins in Native Messaging manifest file I have installed for Chrome,

    ~/Library/Application Support/Google/Chrome/NativeMessagingHosts

    and now, amazingly, my native messaging tool launches as expected when Opera loads my extension! My plans were to use the same native messaging tool for both Chrome and Opera, anyhow.

    So, @kszularz, although it looks ridiculous, this might work, as is. I shall update my bug at DNAWIZ-3730 after doing some more testing.

  • I'm not quite done yet but, so far, it looks like putting my Native Messaging manifest file in Google Chrome's Application Support folder in the user's Home directory is going to work.

    So I've sent an update to DNAWIZ-3797 (My previous comment had wrong DNA number.)

  • Hi @jerrykrinock

    Native messaging is supposed to work as mentioned in the documentation. I've made some minor fixes in the docs, but the point remains that right now Opera looks for the chrome directory. We're re-evaluating again on whether to change this approach or not, but so far, as you have also experienced, it works as is.

  • Thank you, @shwetankdixit. Maybe your changes have not been published yet, but in the documentation I still see this path:

    /Library/Google/Chrome/NativeMessagingHosts/...

    That should be corrected to:

    ~/Library/Application Support/Google/Chrome/NativeMessagingHosts/...

  • @jerrykrinock please check again 🙂 It should be there ...

  • @shwetankdixit, I don't see anything about Linux mentioned in the documentation.

    On my DNA-23526 bug-report I got this answer:

    Could you try using following paths
    /etc/chromium/native-messaging-hosts
    or:
    <OPERA_PROFILE_DIR>/NativeMessagingHosts
    Profile path will be displayed on opera:about page.`
    

    Opera:about doesn't show anything about a google-chrome path, but mentioned path worked at that moment. Please don't blame me for filing more bug reports when it stopped working. The path really changed between versions, without documentation or rationale.

    And it feels wrong and risky:
    If Google-Chrome isn't installed, the google-chrome path is a path any program can create/write to.

    And when you have Chrome installed and decide to drop it because you prefer Opera, and remove Chrome and all of it's settings, suddenly Opera fails. Doesn't make sense to me.

Log in to reply
 

Looks like your connection to Opera forums was lost, please wait while we try to reconnect.