Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get response in Ubuntu #506

Closed
yigitcanustek opened this issue Dec 5, 2022 · 10 comments
Closed

Can't get response in Ubuntu #506

yigitcanustek opened this issue Dec 5, 2022 · 10 comments
Labels
idle Issues and pull requests with no activity for three months.

Comments

@yigitcanustek
Copy link

yigitcanustek commented Dec 5, 2022

I tried every solution path in MDN Native Messaging Docs
(https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging
also
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_manifests)
but can't get response from ping_pong.py.

I copied ping_pong.json(also manifest.json too cause clearly not working with ping_pong.json) that specified in docs, can't response in either. By the way, i must tell that some folders didn't exist while i was trying to copy(e.g. /usr/lib/mozilla/native-messaging-hosts). So i created that folder and copied ping_pong.json to there and still can't get response.

The last thing i need to mention, i need to deleted Firefox, before because the snap installation causes problem to Firefox to find profiles. I removed Firefox then installed without snap installation and able to run Firefox for profile changes seamlessly.

Ubuntu version:
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy

Firefox version:
Mozilla Firefox 107.0.1

@higba
Copy link

higba commented Dec 15, 2022

I am having the same issue but I am running MacOS Monterey 12.6. Mozilla Firefox version 108.0. There is no error, the extension is sending but no response from the application.

@guest271314
Copy link
Contributor

python alone is not an executable in Ubuntu.

$ find /usr/bin/python
find: ‘/usr/bin/python’: No such file or directory

I filed #490 to fix that issue.

Try substituting

#!/usr/bin/env -S python3 -u

for

#!/usr/bin/env python

@yigitcanustek
Copy link
Author

Nope. Still not working.

Also
$ find /usr/bin/python
returns
/usr/bin/python

And yes, i checked the permissions and they all have execute permission.

I think, this is not about Python. Somehow, Firefox is not reading the .json files and can't communicate each other.

@guest271314
Copy link
Contributor

The last time I tested on Nightly it worked. I'll test again later today or tomorrow.

@yigitcanustek
Copy link
Author

Okey. I'll wait the test result but i want to ask where do you put manifest file? I am asking this question because

/usr/lib/mozilla/native-messaging-hosts/.json

and

/usr/lib64/mozilla/native-messaging-hosts/.json

the mozilla folder didn't exist. So, manually created by myself. I think, this issue related to this configuration. Briefly, how to configure this environment? Can you provide ur configurement verbosely?

@guest271314
Copy link
Contributor

Neither. I removed the snap Firefox installation. Then removed snap altogether and fetched Nightly and created the file in ~/.mozilla.

@guest271314
Copy link
Contributor

I created this

~/.mozilla/native-messaging-hosts/<name>.json

per https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_manifests#linux.

@guest271314
Copy link
Contributor

  1. Include error handling in background.js (and optionally just log the port) so you know what is going on
let port = browser.runtime.connectNative("ping_pong");
console.log(port);
// Include error handling so we know what is going on
port.onDisconnect.addListener((err) => {
  if (browser.runtime.lastError) {
    console.warn(browser.runtime.lastError);
  }
  console.error(err.name, err.message);
});
  1. Create the directory native-messaging-hosts in ~/.mozilla;
  2. Open the file ping_pong.json, write the full path on the filesystem to ping_pong.py at "path" value, e.g.,
{
  "name": "ping_pong",
  "description": "Example host for native messaging",
  "path": "/home/user/native-messaging/app/ping_pong.py",
  "type": "stdio",
  "allowed_extensions": [ "ping_pong@example.org" ]
}
  1. Open ping_pong.py and substitute the following shebang for the one in the file, to avoid any ambiguity as to which executable is being called; the -S passed to env enables passing options to the executable called

-S, --split-string=S process and split S into separate arguments;
used to pass multiple arguments on shebang lines

in this case -u, for `

-u : force the stdout and stderr streams to be unbuffered;
this option has no effect on stdin; also PYTHONUNBUFFERED=x

#!/usr/bin/env -S python3 -u

because I do not have the executable python is installed on my machine. If you have the executable python installed on your machine; then omit step 4.;
5. cd to the app directory and make sure ping_pong.py is marked executable $ chmod u+x ping_pong.py;
6. On Firefox or Nightly navigate to about:debugging, click "This Nightly" or "This Firefox", select the "Load Temporary Add-on...", select manifest.json;
7. Click "Inspect";
8. Pin the icon to the toolbar if not already automatically pinned, then click the icon.

Screenshot_2023-01-02_21-18-59

@yigitcanustek
Copy link
Author

Yeah. Finally make it! Thanks.
The causing problem is

#!/usr/bin/env -S python3 -u

with

~/.mozilla path.

I tried

/usr/lib...

path which is firstly specified in docs. I also created file before ops in

~/.mozilla

too but i think i made typo errors.

Thanks again :)

@yigitcanustek
Copy link
Author

I am having the same issue but I am running MacOS Monterey 12.6. Mozilla Firefox version 108.0. There is no error, the extension is sending but no response from the application.

If you are able to solve your problem, i think we close this issue.

@github-actions github-actions bot added the idle Issues and pull requests with no activity for three months. label Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idle Issues and pull requests with no activity for three months.
Projects
None yet
Development

No branches or pull requests

3 participants