Open Bug 1433292 Opened 7 years ago Updated 2 years ago

Make browser.permissions.request() reject when it can't find the browser window to anchor the notification

Categories

(WebExtensions :: Frontend, enhancement, P3)

56 Branch
enhancement

Tracking

(Not tracked)

People

(Reporter: aswan, Unassigned)

References

(Depends on 2 open bugs)

Details

Attachments

(4 files)

We have several related bugs where calling browser.permissions.request() from various contexts leads to a situation where we can't find the browser window to place the permission notification. In these cases, permissions.request() just fails silently, lets fix it to reject in these cases with a useful error message.
I would like to work on this bug. Can you please assign it to me?
Flags: needinfo?(aswan)
Sure, and thanks for your interest! Have you downloaded and built the Firefox source code locally? If not, that's a good place to start: https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions/Simple_Firefox_build For this bug, artifact builds will be suitable and they will save you some time, disk space, etc: https://developer.mozilla.org/en-US/docs/Artifact_builds Once you're ready to work on the bug, the code in question is here: https://searchfox.org/mozilla-central/source/toolkit/components/extensions/ext-permissions.js#44 In this case the variable browser is a XUL <browser> element and we want to know if it corresponds to a browser tab or to something else (like a popup, sidebar, etc.) I think the test to add there is something like: ``` if (browser.ownerGlobal.gBrowser && browser.ownerGlobal.gBrowser.getTabForBrowser(browser)) { } ``` You can start out by testing this manually, once you've got something working we can talk about how to write an automated test. It looks like you already know how to use the needinfo flag, please feel free to use it for any questions that you have along the way. Thanks, good luck, and don't hesitate to ask questions!
Assignee: nobody → cs16btech11030
Flags: needinfo?(aswan)
Hey ssirowa! Just wanted to check in and see how it's going with this bug.
Flags: needinfo?(cs16btech11030)
I was a bit busy with exams. I will submit the patch by Tuesday. I apologize for the delay.
Flags: needinfo?(cs16btech11030)
Hey ssirowa! Because it's been awhile since we've heard from you, we're going to unassign you from this bug and open it up to other contributors. If you'd still like to submit a patch, please feel free to re-assign yourself and submit!
Assignee: cs16btech11030 → nobody
Hi Amy, Yeah you can work on this, thanks. And you are correct, that file recently moved, and you've got the right one. If this is your first time trying to code on firefox, check out this (and linked) pages for instructions: https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions/Simple_Firefox_build If you have any questions, feel free to need-info me or Andrew.
Amy, thanks for your interest. The patches that recently landed for bug 1382953 may have made this bug irrelevant, so a good first step would be to see if you can reproduce it at all. That would entail writing a test extension that uses the permissions.request() api from various types of events (context menu clicks, sidebars, options pages, etc) and seeing if it fails to show a prompt to the user in any of those cases. As Tom said, please feel free to use needinfo if you have more questions (click the "Need more information" box at the bottom of this page when adding a comment and type either :aswan or :zombie into the text box there)
I wrote a test extension that use permission.request() in normal pages, context menus, options pages, and sidebars. The first three worked and prompted the user for permission, but when I request permission in the sidebar, I got an "JavaScript error: moz-extension://5714f483-cd0c-dc45-882c-930b5b97849b/sidebar/panel.js, line 16: TypeError: browser.tabs is undefined" error in my terminal's console. Is that the intended results and this bug is irrelevant, or is a different result desired?
Flags: needinfo?(aswan)
Can you share the full code for your test extension somewhere?
Flags: needinfo?(aswan)
I haven't really done much with extension before, so all I did was use mdn's own extension demo examples (https://github.com/mdn/webextensions-examples) and added link that request permission - I requested history permission in this case. I put the code in https://github.com/amychan331/testing-webextension. Directory extension-permission combines mdn's permissions and menu-demo examples, while the extension-options-sidebar directory combines the annotate-page and favourite-colour.
Flags: needinfo?(aswan)
When I load your sample extension, I don't get the browser.tabs error you reported in comment 9 but I do get an error since the code to work back from the sidebar page where extension is running to the surrounding chrome window doesn't do the right thing. That code is here: https://searchfox.org/mozilla-central/source/browser/modules/ExtensionsUI.jsm#29-34 Its a little crude but an expedient fix would be to add an additional check such as `if (browser.getAttribute("id") == "webext-panels-browser")` But first we have to get past the browser.tabs error, what Firefox version are you running?
Flags: needinfo?(aswan) → needinfo?(amy_yyc)
Interesting - now that I try it again, I am getting the error from ExtensionsUI.jsm too. The error message is now "JavaScript error: resource:///modules/ExtensionsUI.jsm, line 400: TypeError: window.PopupNotifications is null". I wonder if I did something and saved it without realizing it? As for the Firefox version, I am using Nightly, 61.0a1.
Flags: needinfo?(amy_yyc)
Product: Toolkit → WebExtensions
Flags: needinfo?(aswan)
Sidebar bug was reported in bug 1493396. I just tested permissions.request on Nightly (same version as that other bug): - Background page: Anchored to current tab. - Popup: Silent failure, no errors in console. - Sidebar: Rejected - bug 1493396 - Options page: untested, supposedly works after bug 1382953
See Also: → 1493396
Bug for popup is here: bug 1432083
See Also: → 1432083
Hey, I would like to work on this bug.
Hey Arica, go for it! If you haven't already done so, you might want to look at the onboarding documentation here: https://wiki.mozilla.org/WebExtensions/Contribution_Onramp If you need any help, please need-info :aswan. Happy bug fixing!
Assignee: nobody → aricachakraborty18
Flags: needinfo?(aswan)
Thanks,i'm going through the available material to set-up my environment and get started.

Hey Arica, how's it going with this bug?

Flags: needinfo?(aricachakraborty18)

Hi,
I would like to work on this bug. Can you please assign it to me!
Thanks

Flags: needinfo?(cneiman)
Assignee: aricachakraborty18 → suhail.singhyo
Flags: needinfo?(cneiman)
Flags: needinfo?(aricachakraborty18)
Attachment #9043196 - Attachment description: Bug 1433292 - Make browser.permissions.request() reject when it can't find the browser window to anchor the notification, r=aswan → Bug 1433292 - Browser.permissions.request() reject when it can't find the browser window to anchor the notification, r=aswan
Attachment #9043196 - Attachment description: Bug 1433292 - Browser.permissions.request() reject when it can't find the browser window to anchor the notification, r=aswan → Bug 1433292 - Make Browser.permissions.request() reject when it can't find the browser window to anchor the notification, r=aswan

Hi
The code has to be changed in getTabBrowser function, if I am not wrong.
Please correct me if I am missing something.
Thanks

Flags: needinfo?(aswan)

Do you mean getTabForBrowser() ? If so, I'm not sure what you're suggesting, what would you change in that function?

Flags: needinfo?(aswan)

Hey Suhail, how's it going with this bug? Can we help unblock you?

Flags: needinfo?(suhail.singhyo)

Hey Suhail, it looks like you're getting close! Aswan added some comments in Phabricator -- want to take a look at those and finish this off?

Mentor: aswan → mstriemer

I'll help mentor this patch now. Let me know if you have any questions.

Per conversation over IRC with Suhail, this bug is being re-opened for other contributors. If you would like to work on this, please submit a patch via Phabricator; once your patch has been submitted, we will assign you to the bug.

Flags: needinfo?(suhail.singhyo)
Assignee: suhail.singhyo → nobody

Hey, is this bug still open ? Can i work in this bug ?

Not sure if this is related, but in my case browser.permissions is undefined in a certain context (iframe with src="moz-extension://...").

(In reply to Thomas Oberndörfer from comment #32)

Not sure if this is related, but in my case browser.permissions is undefined in a certain context (iframe with src="moz-extension://...").

That is an unrelated bug: bug 1443253

Assignee: nobody → suhail.singhyo
Status: NEW → ASSIGNED
Assignee: suhail.singhyo → nobody
Status: ASSIGNED → NEW

Hi Rob and Luca. I am an outreachy intern, can I work on this bug please?

Hi Naimat, feel free to work on this bug! We'll assign it to you once you have a PR. Here's a link to our onboarding documentation to help you get started: https://wiki.mozilla.org/WebExtensions/Contribution_Onramp

Hello Rob Wu, I am an Outreachy applicant and I'd like to work on this please

Hi, Is someone working on this?, If not I would love to take on this issue :)

Hi, Just a friendly reminder for this comment#37

Flags: needinfo?(mstriemer)

No contributor is currently working on this issue at the moment, redirecting the needinfo to me to look if previous contributor got stuck because of some lack of guidance details.

Flags: needinfo?(mstriemer) → needinfo?(lgreco)
Mentor: mstriemer → lgreco
Flags: needinfo?(lgreco)

https://phabricator.services.mozilla.com/D98574 is already working towards a fix that may also fix this bug.

bug 1493396 is the other remaining bug (from the list in comment 14).

Mentor: lgreco
Depends on: 1679925
Keywords: good-first-bug

Should i fix viewType == "background" in this bug, but still check gBrowser.getTabForBrowser(browser) and reject with an error message?

Flags: needinfo?(rob)

Created bug 1763915.

Flags: needinfo?(rob)
Depends on: 1763915
Severity: normal → S3
See Also: → 1868551
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: