Can't use browser.permissions.request from about:addons preferences page (win.PopupNotifications is undefined)

NEW
Unassigned

Status

()

Toolkit
WebExtensions: Frontend
P3
normal
7 months ago
28 days ago

People

(Reporter: kanru, Unassigned)

Tracking

({dev-doc-needed, regression})

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [permissions])

Attachments

(1 attachment)

(Reporter)

Description

7 months ago
While testing the Gecko Profiler Addon, I need to set the profilerViewerURL from the preferences page, which the addon calls:

  const granted = await browser.permissions.request({
      origins: [getPermissionFromProfileViewerURL(optionsObj[key])],
  });

But failed immediately with unknown error.

The error from browser toolbox console is:

  15:35:13.472 win.PopupNotifications is undefined 1 ExtensionsUI.jsm:441
	showPermissionsPrompt/< resource:///modules/ExtensionsUI.jsm:441:7
	showPermissionsPrompt resource:///modules/ExtensionsUI.jsm:417:12
	observe resource:///modules/ExtensionsUI.jsm:241:15
	getAPI/request_parent/allow< chrome://extensions/content/ext-permissions.js:57:15
	request_parent chrome://extensions/content/ext-permissions.js:47:31
	InterpretGeneratorResume self-hosted:1276:8
	next self-hosted:1183:9
	request_parent self-hosted:947:17
	call/result< resource://gre/modules/ExtensionParent.jsm:696:57
	withPendingBrowser resource://gre/modules/ExtensionParent.jsm:395:26
	next self-hosted:1183:9
	call resource://gre/modules/ExtensionParent.jsm:695:20
	next self-hosted:1183:9
15:35:13.473 Error: An unexpected error occurred 1 options.js:36:11
	saveOptions moz-extension://6aa65102-9a9c-406d-95f4-81d301e7b452/options.js:36:11


It looks like win.PopupNotifications is undefined for about:addons page.
(Reporter)

Updated

7 months ago
Summary: Can't using browser.permissions.request from options page → Can't use browser.permissions.request from about:addons preferences page
I guess we need to map these <browser>s to the top-level tab browser. We can either do that in ExtensionUI, or re-use the code we have elsewhere that special cases about:addons browsers when setting tab IDs.

But this makes me suspect we don't handle this properly for things like popup or sidebar browsers either. I suppose, given that popups are auto-close, we'd run into the normal auto-close issues with the permission prompts there, but sidebars should arguably be able to handle this.
Flags: needinfo?(aswan)
Component: WebExtensions: General → WebExtensions: Frontend
Is there a workaround for this?

Comment 4

7 months ago
(In reply to Markus Stange [:mstange] from comment #3)
> Is there a workaround for this?

Its probably not very satisfying but for now, opening the preferences in a separate tab i guess?
That works, thanks! The URL is moz-extension://73bc7cd1-4322-2745-b8cc-9d1a6e0a27b1/options.html for me.

Comment 6

7 months ago
The uuid in that URL is local to your installation.  But you can put the "open_in_tab" property into options_ui in the extension manifest to automatically have preferences open in a tab:
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/options_ui#Syntax

Updated

7 months ago
Keywords: dev-doc-needed
Priority: -- → P5
Whiteboard: [permissions]

Comment 7

7 months ago
(In reply to Kris Maglione [:kmag] from comment #1)
> I guess we need to map these <browser>s to the top-level tab browser. We can
> either do that in ExtensionUI, or re-use the code we have elsewhere that
> special cases about:addons browsers when setting tab IDs.
> 
> But this makes me suspect we don't handle this properly for things like
> popup or sidebar browsers either. I suppose, given that popups are
> auto-close, we'd run into the normal auto-close issues with the permission
> prompts there, but sidebars should arguably be able to handle this.

Yeah, agreed.  Between having a full plate and not knowing the popup/sidebar stuff very well, I'm skeptical that I can do this in 57.  But P5 seems too low, bumping it up a wee bit.
Flags: needinfo?(aswan)
Priority: P5 → P3

Comment 8

6 months ago
Created attachment 8906388 [details]
testcase.zip

I attach a test case which permission prompt:
  - doesn't display on Firefox 57.0a1 (2017-09-10) ;
  - works on Firefox 55.0.3.

Steps:
  1. dezip attach file
  2. load tempary add-on ;
  3. go to preference of add-on ;
  4. click on "Remove" button ;
  5. click on "Request" button : permission prompt doesn't display.

Browser console:
// Click on "Remove" button.

19:24:01,361 removed = true 1 script.js:7:9

// Click on "Request" button.

19:24:03,462 win.PopupNotifications is undefined 1 ExtensionsUI.jsm:329
	showPermissionsPrompt/< resource:///modules/ExtensionsUI.jsm:329:7
	showPermissionsPrompt resource:///modules/ExtensionsUI.jsm:305:12
	observe resource:///modules/ExtensionsUI.jsm:241:15
	getAPI/request/allow< chrome://extensions/content/ext-permissions.js:55:15
	request chrome://extensions/content/ext-permissions.js:45:31
	next self-hosted:1190:9

19:24:03,476 granted: 1 script.js:18:9

19:24:03,478 Error: An unexpected error occurred
Trace de la pile :
Async*@moz-extension://76b70b4b-8122-4179-a315-4ab599f1c066/script.js:15:5
EventListener.handleEvent*@moz-extension://76b70b4b-8122-4179-a315-4ab599f1c066/script.js:14:1
 1 script.js:19:9
	<anonyme> moz-extension://76b70b4b-8122-4179-a315-4ab599f1c066/script.js:19:9
	(Asynchrone : promise callback)
	<anonyme> moz-extension://76b70b4b-8122-4179-a315-4ab599f1c066/script.js:15:5
	(Asynchrone : EventListener.handleEvent)
	<anonyme> moz-extension://76b70b4b-8122-4179-a315-4ab599f1c066/script.js:14:1

Updated

4 months ago
Duplicate of this bug: 1411873

Comment 10

3 months ago
I get the same message when requesting permissions from background.js + contextMenus.onClicked

Shortened code:

  chrome.contextMenus.onClicked.addListener(() => {
    chrome.permissions.request({
      origins: [
        `https://google.com/*`
      ]
    }, granted => {
      // It never reaches this place
    });
  });



Full code: https://github.com/bfred-it/webext-domain-permission-toggle/blob/05bc4be/webext-domain-permission-toggle.js#L31-L35

Comment 11

3 months ago
Can confirm this problem with 57.0.2.

When I request permissions
- from a popup: nothing happens, 
- from the about page: nothings happens, and I get that error message (unexpected error occured)
- from a separate tab: it works.

Comment 12

3 months ago
> Can confirm this problem with 57.0.2

... and also with with 59.0a1 (2017-12-07)
See Also: → bug 1422605
Summary: Can't use browser.permissions.request from about:addons preferences page → Can't use browser.permissions.request from about:addons preferences page (win.PopupNotifications is undefined)
(In reply to Sébastien Règne from comment #8)
>   - doesn't display on Firefox 57.0a1 (2017-09-10) ;
>   - works on Firefox 55.0.3.

Thanks for the tip!  This was regressed by bug 1357486.
Blocks: 1357486
Keywords: regression
See Also: → bug 1432083
You need to log in before you can comment on or make changes to this bug.