Closed Bug 1630415 Opened 4 years ago Closed 3 years ago

make nativeMessaging an optional permission

Categories

(WebExtensions :: General, enhancement, P1)

enhancement

Tracking

(firefox87 fixed)

RESOLVED FIXED
87 Branch
Tracking Status
firefox87 --- fixed

People

(Reporter: mixedpuppy, Assigned: mixedpuppy)

References

(Blocks 1 open bug)

Details

(Keywords: dev-doc-complete)

Attachments

(1 file)

No description provided.
Priority: -- → P1
Severity: -- → N/A
Assignee: nobody → mixedpuppy
Status: NEW → ASSIGNED
Pushed by scaraveo@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/4eebd98e4997
allow nativeMessaging in optional permissions r=rpl

Backed out for causing xpcshell failures on test_ext_permissions_api.js

backout: https://hg.mozilla.org/integration/autoland/rev/37c94de87a83f91a2d79f9e0b93065984022623e

push: https://treeherder.mozilla.org/jobs?repo=autoland&revision=4eebd98e49971b977dbd73b7ca23657d87c94542&searchStr=xpcshell&group_state=expanded&selectedTaskRun=U_Yk7hRZST-Vpy3fsh9eMg.0

failure log: https://treeherder.mozilla.org/logviewer?job_id=328593139&repo=autoland&lineNumber=3215

[task 2021-02-02T17:30:28.841Z] 17:30:28 INFO - TEST-START | xpcshell.ini:toolkit/components/extensions/test/xpcshell/test_ext_permissions_api.js
[task 2021-02-02T17:30:29.689Z] 17:30:29 WARNING - TEST-UNEXPECTED-FAIL | xpcshell.ini:toolkit/components/extensions/test/xpcshell/test_ext_permissions_api.js | xpcshell return code: 0
[task 2021-02-02T17:30:29.689Z] 17:30:29 INFO - TEST-INFO took 852ms
[task 2021-02-02T17:30:29.689Z] 17:30:29 INFO - >>>>>>>
[task 2021-02-02T17:30:29.689Z] 17:30:29 INFO - (xpcshell/head.js) | test MAIN run_test pending (1)
[task 2021-02-02T17:30:29.689Z] 17:30:29 INFO - (xpcshell/head.js) | test run_next_test 0 pending (2)
[task 2021-02-02T17:30:29.689Z] 17:30:29 INFO - (xpcshell/head.js) | test MAIN run_test finished (2)
[task 2021-02-02T17:30:29.691Z] 17:30:29 INFO - running event loop
[task 2021-02-02T17:30:29.691Z] 17:30:29 INFO - xpcshell.ini:toolkit/components/extensions/test/xpcshell/test_ext_permissions_api.js | Starting check_remote
[task 2021-02-02T17:30:29.691Z] 17:30:29 INFO - (xpcshell/head.js) | test check_remote pending (2)

Flags: needinfo?(mixedpuppy)
Pushed by scaraveo@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/5b295e666e95
allow nativeMessaging in optional permissions r=rpl
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 87 Branch
Flags: needinfo?(mixedpuppy)
Keywords: dev-doc-needed

I'm running Firefox version 90 and have attempted to run the native message example after changing its manifest to use "optional_permissions": ["nativeMessaging"]. Doing so results in the error Uncaught TypeError: browser.runtime.connectNative is not a function which according to the troubleshooting guide indicates that the nativeMessaging permission has not been provided. Reverting to the use of "permissions": ["nativeMessaging"] results in no error. What am I overlooking?

Flags: needinfo?(mixedpuppy)

Optional permission means extension needs to request it from the user, and have it granted. For example, check out the test that landed with the patch:

https://searchfox.org/mozilla-central/rev/00977c4e37/toolkit/components/extensions/test/xpcshell/test_ext_native_messaging.js#111

Flags: needinfo?(mixedpuppy)

Thanks for the reminder. However, I appeared to be unable to figure out how to add the request to the background script of the native messaging example (https://github.com/mdn/webextensions-examples/blob/master/native-messaging/add-on/background.js). Can you offer any suggestions?

Flags: needinfo?(tomica)

Can nativeMessaging still be declared as a permissions, or can only be handled as an optional permissions

Flags: needinfo?(mixedpuppy)

(In reply to Richard Bloor from comment #9)

Can nativeMessaging still be declared as a permissions, or can only be handled as an optional permissions

yes, it can be used in both permissions and optional_permissions.

Flags: needinfo?(mixedpuppy)

(In reply to Richard Bloor from comment #8)

Thanks for the reminder. However, I appeared to be unable to figure out how to add the request to the background script of the native messaging example (https://github.com/mdn/webextensions-examples/blob/master/native-messaging/add-on/background.js). Can you offer any suggestions?

Calling browser.permissions.request needs to happen while handing user input, I'm guessing that may be the reason why you had issues to call it from the background page.

An easy way to deal with it could be to create an example that uses browser.permissions.request and browser.runtime.connectNative from an extension page that is visible to the user and can have a button with a listener to call browser.permissions.request (you could likely take https://github.com/mdn/webextensions-examples/tree/master/permissions as inspiration for the permissions requesting part and mix that with the native-messaging example).

Let me know if this helped you to figure out how to create the new example (or if it is not working yet, in that case feel free to push a branch with your preliminary version on github and link me that to me).

Flags: needinfo?(tomica)

Documentation review request. Changes for this are now available:

The native message in web extension example continues to work with a permission declaration, issue Update native messaging example to use optional permission #8237 has been created with a view to amending the example to use optional_permissions

Flags: needinfo?(mixedpuppy)
Flags: needinfo?(lgreco)

Thanks Richard, I'm clearing the needinfo assigned to me here on bugzilla given that I have already commented in the pull requests linked in comment 12 (and accepted both).

Flags: needinfo?(lgreco)
Flags: needinfo?(mixedpuppy)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: