Closed
Bug 1438465
Opened 7 years ago
Closed 7 years ago
sidebarAction.isOpen callback cannot call sidebarAction.open() or sidebarAction.close()
Categories
(WebExtensions :: Frontend, enhancement)
WebExtensions
Frontend
Tracking
(Not tracked)
RESOLVED
DUPLICATE
of bug 1398833
People
(Reporter: rhubscher, Unassigned)
References
()
Details
I want to implement a toggle of the sidebar from a sidebarAction.
In order to do that I did the following code that also detects if we have the isOpen API yet:
> // Handle onClick event for the toolbar button
> browser.browserAction.onClicked.addListener(() => {
> if (browser.sidebarAction.hasOwnProperty('isOpen')) {
> browser.sidebarAction.isOpen({}).then(isOpen => {
> console.log("Sidebar open", isOpen);
> if (isOpen) {
> browser.sidebarAction.close();
> } else {
> browser.sidebarAction.open();
> }
> });
> } else {
> browser.sidebarAction.open();
> }
> });
I even tried to use async/await
> async function toggleSidebar() {
> if (browser.sidebarAction.hasOwnProperty('isOpen')) {
> const isOpen = await browser.sidebarAction.isOpen({});
> console.log("Sidebar open", isOpen);
> if (isOpen) {
> browser.sidebarAction.close();
> } else {
> browser.sidebarAction.open();
> }
> } else {
> browser.sidebarAction.open();
> }
> }
>
> // Handle onClick event for the toolbar button
> browser.browserAction.onClicked.addListener(toggleSidebar);
But I have the following errors:
> Sidebar open true background.js:200:5
> Error: sidebarAction.close may only be called from a user input handler
> Sidebar open false background.js:200:5
> Error: sidebarAction.open may only be called from a user input handler
I think if sidebarAction.close or sidebarAction.open are called from an addListener even if they are nested deep down they should be accepted because you may want to way for a data load before opening them for instance.
Reporter | ||
Updated•7 years ago
|
Reporter | ||
Comment 1•7 years ago
|
||
IMHO, if we don't want to change too many things, making the async function workflow to work would be the best first step.
Comment 2•7 years ago
|
||
The title of the duplicate bug is a little misleading, but it is about propagating the "handling user input" across callbacks/promises
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → DUPLICATE
Reporter | ||
Comment 3•7 years ago
|
||
If it is a duplicate I believe it is more a duplicate of Bug 1408129 than Bug 1398833 but in both case we have this issue with a nested call to close or open that is not detected as a user action.
Comment 4•7 years ago
|
||
I don't see any connection to bug 1408129
Reporter | ||
Comment 5•7 years ago
|
||
> I don't see any connection to bug 1408129
According to its title it is about propagating the "handling user input" across callbacks/promises
Updated•6 years ago
|
Product: Toolkit → WebExtensions
You need to log in
before you can comment on or make changes to this bug.
Description
•