permissions.request() does not work in sidebar, rejected with Error: An unexpected error occurred
Categories
(WebExtensions :: General, defect, P2)
Tracking
(firefox101 fixed)
| Tracking | Status | |
|---|---|---|
| firefox101 | --- | fixed |
People
(Reporter: robwu, Assigned: kernp25, Mentored)
References
Details
(Keywords: good-first-bug)
Attachments
(2 files)
Comment 1•7 years ago
|
||
| Reporter | ||
Comment 2•7 years ago
|
||
Comment 3•7 years ago
|
||
Updated•7 years ago
|
Updated•7 years ago
|
Comment 4•7 years ago
|
||
Comment 5•6 years ago
|
||
Leaving a P2, missing permission prompt causing breakage sidebar extensions.
| Reporter | ||
Comment 6•5 years ago
|
||
permissions.request is implemented here: https://searchfox.org/mozilla-central/rev/919607a3610222099fbfb0113c98b77888ebcbfb/toolkit/components/extensions/parent/ext-permissions.js#34-99
It relies on the context.pendingEventBrowser || context.xulBrowser; member to find the <browser> . This <browser> is where the notification is shown, which is currently only implemented for tabs, not for sidebars. To fix this bug, we should use the selected tab of the sidebar instead (in the window where the sidebar is shown).
To resolve this bug, you need to find when the sidebar's <browser> is used. The element can be identified by one of its attributes (the element is created at https://searchfox.org/mozilla-central/rev/919607a3610222099fbfb0113c98b77888ebcbfb/browser/base/content/webext-panels.js#36-45). The Browser Toolbox can be used directly debug the sidebar and its internals - see https://developer.mozilla.org/en-US/docs/Tools/Browser_Toolbox
Once you're able to identify calls from the sidebar, get the top window and find the selected tab browser. Hint: The top-level window containing the sidebar can be found via the browser.ownerGlobal.windowRoot property.
To make sure that the functionality works as expected, unit tests should be written. E.g. based on the manual test from the bug report.
Comment 7•5 years ago
|
||
Hello, I am new to contributing to Bugzilla can you assigned me to this issue so that I can learn to fix these bugs and also suggest to me how can Is start working on this bug to fix it.
| Reporter | ||
Comment 8•5 years ago
|
||
(In reply to Falguni Islam from comment #7)
Hello, I am new to contributing to Bugzilla can you assigned me to this issue so that I can learn to fix these bugs and also suggest to me how can Is start working on this bug to fix it.
Hello, coincidentally someone else has started on a patch that may also address this bug (https://phabricator.services.mozilla.com/D98574). I suggest that you try a different bug. To get started, see the guide at https://wiki.mozilla.org/WebExtensions/Contribution_Onramp (this page also links to a list of other bugs where you can choose from).
| Reporter | ||
Comment 10•4 years ago
|
||
This bug can also be triggered when permissions.request is called in response to commands.onCommand from the background page (in which case context.pendingEventBrowser is null and context.xulBrowser is the background <browser>.
window is the hidden window (https://searchfox.org/mozilla-central/rev/59e797b66f5ce8a27ede0e7677688931be7aed20/toolkit/components/extensions/ExtensionParent.jsm#1137), which doesn't have a UI.
Comment 11•4 years ago
|
||
Notice that if keystroke is assigned to browser action then everything works right so window is that code path is correct. The problem happens when a shortcut is defined namely for user command handled by commands.onCommand. So siblings entries from extension manifest behaves quite differently (from Bug #1721428 marked as a duplicate of this one). I have not tried page action though.
Comment 12•4 years ago
|
||
There are some other bugs related to context of permission popup: Bug #1679925 for inactive tab context menu and mention of this issue in Bug #1433292 comment 14.
Comment 13•4 years ago
|
||
Hello. This is Vaidehi. I am a new contributor. Can I work on this issue?
| Assignee | ||
Comment 14•4 years ago
|
||
(In reply to Vaidehi A from comment #13)
Hello. This is Vaidehi. I am a new contributor. Can I work on this issue?
| Reporter | ||
Comment 15•4 years ago
|
||
Hi Vaidehi, sure you can. Have you read the context in this bug report, comment 6 in particular?
Feel free to ask questions if you have doubts.
Comment 16•4 years ago
|
||
Thank you Rob. I was able to reproduce this. But, I haven't really gone through comment 6 context. Will work on it and let you know.
Comment 17•4 years ago
|
||
Hi Rob.
First-of-all, there are some differences which I observed in the expected results mentioned by you.
- No matter what the value of
extensions.webextOptionalPermissionPromptsis, I never get a permission prompt for step 3. However, I don't get the error whenextensions.webextOptionalPermissionPromptsis set to false, when I click on permissions.request (<all_urls>). - When
extensions.webextOptionalPermissionPromptsis false, at step 6 pop up I get the tab's url instead of undefined.
From what I have understood, I think here the bug is that request for permissions is not being created for sidebars. For that, we need to find <browser> element for sidebar. However, I am not getting how to do it exactly.
To resolve this bug, you need to find when the sidebar's <browser> is used. The element can be identified by one of its attributes (the element is created at https://searchfox.org/mozilla-central/rev/919607a3610222099fbfb0113c98b77888ebcbfb/browser/base/content/webext-panels.js#36-45). The Browser Toolbox can be used directly debug the sidebar and its internals - see https://developer.mozilla.org/en-US/docs/Tools/Browser_Toolbox
Can you explain it a little - how to identify when the sidebar's <browser> is used and how to use attributes for it (using browser toolbox)?
| Reporter | ||
Comment 18•4 years ago
|
||
(In reply to Vaidehi A from comment #17)
Hi Rob.
First-of-all, there are some differences which I observed in the expected results mentioned by you.
- No matter what the value of
extensions.webextOptionalPermissionPromptsis, I never get a permission prompt for step 3. However, I don't get the error whenextensions.webextOptionalPermissionPromptsis set to false, when I click on permissions.request (<all_urls>).
That observation is this bug. A prompt should be seen, but because the prompt UI cannot be anchored to the right <browser> element, the prompt doesn't appear.
- When
extensions.webextOptionalPermissionPromptsis false, at step 6 pop up I get the tab's url instead of undefined.
With extensions.webextOptionalPermissionPrompts set to false, the prompt UI is skipped and any requests are silently approved. Getting the tab's URL is what would happen if the prompt were to show up, followed by the user approving the prompt.
From what I have understood, I think here the bug is that request for permissions is not being created for sidebars. For that, we need to find <browser> element for sidebar. However, I am not getting how to do it exactly.
To resolve this bug, you need to find when the sidebar's <browser> is used. The element can be identified by one of its attributes (the element is created at https://searchfox.org/mozilla-central/rev/919607a3610222099fbfb0113c98b77888ebcbfb/browser/base/content/webext-panels.js#36-45). The Browser Toolbox can be used directly debug the sidebar and its internals - see https://developer.mozilla.org/en-US/docs/Tools/Browser_Toolbox
Can you explain it a little - how to identify when the sidebar's <browser> is used and how to use attributes for it (using browser toolbox)?
At the start of comment 6, I pointed to the code where the permissions.request handler is implemented. With the Browser Toolbox, you can put a breakpoint after the line where the browser variable is initialized, and trigger the permissions.request call via the test case. After triggering the test case, the breakpoint will be triggered and you can use the console to examine the browser variable and anything related to it to get a better understanding of how everything works.
As you can see from the code in webext-panels.js, the sidebar is hosted in a <browser> with the "webext-panels-browser" ID. So a way to identify the browser is to check the condition browser.id === "webext-panels-browser".
Then, as mentioned at the bottom of comment 6, the other part of the solution is
Once you're able to identify calls from the sidebar, get the top window and find the selected tab browser. Hint: The top-level window containing the sidebar can be found via the
browser.ownerGlobal.windowRootproperty.
The snippet above shows how one can get the top-level window containing the sidebar, the part of getting the selected tab browser is to read the .gBrowser.selectedBrowser property of it.
Comment 19•4 years ago
|
||
(In reply to Rob Wu [:robwu] from comment #18)
With
extensions.webextOptionalPermissionPromptsset tofalse, the prompt UI is skipped and any requests are silently approved.
The cited phrase reminded me the Bug #1744960 with the prompt for external scheme handler (regular page vs. add-on discrepancy of behavior).
| Reporter | ||
Comment 20•4 years ago
|
||
(In reply to max from comment #19)
(In reply to Rob Wu [:robwu] from comment #18)
With
extensions.webextOptionalPermissionPromptsset tofalse, the prompt UI is skipped and any requests are silently approved.The cited phrase reminded me the Bug #1744960 with the prompt for external scheme handler (regular page vs. add-on discrepancy of behavior).
That referenced bug is not related at all. This preference defaults to true and can be set to false for testing purposes.
Comment 21•4 years ago
|
||
(In reply to Rob Wu [:robwu] from comment #20)
(In reply to max from comment #19)
(In reply to Rob Wu [:robwu] from comment #18)
With
extensions.webextOptionalPermissionPromptsset tofalse, the prompt UI is skipped and any requests are silently approved.The cited phrase reminded me the Bug #1744960 with the prompt for external scheme handler (regular page vs. add-on discrepancy of behavior).
That referenced bug is not related at all. This preference defaults to true and can be set to false for testing purposes.
Thank you for the clarification. Almost certainly I was wrong and I added more confusion by the imprecise quote. I never thought that extensions.webextOptionalPermissionPrompts might be relevant. Actually I associated "because the prompt UI cannot be anchored to the right <browser> element, the prompt doesn't appear." and "any requests are silently approved" with the external scheme handler popup. Sorry for the noise.
| Assignee | ||
Comment 22•4 years ago
|
||
(In reply to Rob Wu [:robwu] from comment #10)
This bug can also be triggered when
permissions.requestis called in response tocommands.onCommandfrom the background page (in which casecontext.pendingEventBrowserisnullandcontext.xulBrowseris the background<browser>.
windowis the hidden window (https://searchfox.org/mozilla-central/rev/59e797b66f5ce8a27ede0e7677688931be7aed20/toolkit/components/extensions/ExtensionParent.jsm#1137), which doesn't have a UI.
Then we must use windowTracker.topWindow to get the browser? Because, browser.ownerGlobal.windowRoot doesn't work in this case!
| Reporter | ||
Comment 23•4 years ago
|
||
windowTracker.topWindow would return the active browser window;
If you are interested in the browser element, use tabTracker.activeTab.linkedBrowser instead.
| Assignee | ||
Comment 24•4 years ago
|
||
I mean, can the patch use windowTracker.topWindow.gBrowser.selectedBrowser to also fix the bug in comment 10?
Or is this bug only for the sidebar?
Because, you said we must check for browser.id === "webext-panels-browser"?
| Reporter | ||
Comment 25•4 years ago
|
||
A sidebar is always associated with a window, so it would make more sense to use that window.
In practice, a permission request from a sidebar will end up in the same window as the topWindow, but in theory it's possible for the window focus to change before the permission prompt appears.
As for gBrowser, that's a desktop-only property. The snippet that I shared in comment 23 is the general code that can be used for code shared between desktop and mobile code. (permissions.request doesn't work on mobile atm, but that's actively being worked on in bug 1601420.
| Assignee | ||
Comment 26•4 years ago
|
||
Updated•4 years ago
|
Comment 27•4 years ago
|
||
Comment 28•4 years ago
|
||
| bugherder | ||
Description
•