-
Notifications
You must be signed in to change notification settings - Fork 75
Proposal: close() Method for the sidePanel API #837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
37ea058
6d34867
419caa5
f9b2fcb
96a097c
255679a
e0db95e
bbb14d3
616013b
199ab84
4eb6c07
5544257
2ff64ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,142 @@ | ||||||||||||||
| # New close() Method for the sidePanel API | ||||||||||||||
|
|
||||||||||||||
| **Summary** | ||||||||||||||
|
|
||||||||||||||
| Proposal to introduce a programmatic close method for the side panel API. | ||||||||||||||
|
|
||||||||||||||
| **Document Metadata** | ||||||||||||||
|
|
||||||||||||||
| **Author:** [hharshas](https://github.com/hharshas) | ||||||||||||||
|
|
||||||||||||||
| **Sponsoring Browser:** Chromium | ||||||||||||||
|
|
||||||||||||||
| **Contributors:** [hharshas](https://github.com/hharshas) ([Summer Of | ||||||||||||||
| Code](https://summerofcode.withgoogle.com/)), mentor: oliverdunk, solomonkinard | ||||||||||||||
|
|
||||||||||||||
| **Created:** 2025-05-27 | ||||||||||||||
|
|
||||||||||||||
| **Related Issues:** [#521](https://github.com/w3c/webextensions/issues/521), | ||||||||||||||
| [#chromium](https://issues.chromium.org/issues/403765214) | ||||||||||||||
|
|
||||||||||||||
| ## Motivation | ||||||||||||||
|
|
||||||||||||||
| ### Objective | ||||||||||||||
|
|
||||||||||||||
| What does this API enable? | ||||||||||||||
| - `sidePanel.close()` method will allow the sidebar to close programmatically. | ||||||||||||||
|
|
||||||||||||||
| Why do we need it? | ||||||||||||||
| - Currently, extensions cannot directly close their own side panel from the | ||||||||||||||
| background script, developers have to: | ||||||||||||||
| 1. Send a message from a background script to the side panel. | ||||||||||||||
| 2. Call `window.close()` from the side panel window on message delivery. | ||||||||||||||
|
|
||||||||||||||
| This event aims to give developers an easier control. | ||||||||||||||
|
|
||||||||||||||
| #### Use Cases | ||||||||||||||
|
|
||||||||||||||
| Programmatic Control: | ||||||||||||||
| - An extension could automatically close the panel after completing an action or | ||||||||||||||
| when certain conditions are met. For example, an extension that helps users fill | ||||||||||||||
| out a form could close the side panel automatically once the form is submitted. | ||||||||||||||
| This ensures the side panel only stays open while it’s needed, | ||||||||||||||
| streamlining the user experience. | ||||||||||||||
|
|
||||||||||||||
| ### Known Consumers | ||||||||||||||
|
|
||||||||||||||
| [The Chromium bug](https://issues.chromium.org/issues/403765214) has a significant | ||||||||||||||
| amount of developer interest and the discussions on the issue shows the same. | ||||||||||||||
|
|
||||||||||||||
| ## Specification | ||||||||||||||
|
|
||||||||||||||
| ### Schema | ||||||||||||||
|
|
||||||||||||||
| ```typescript | ||||||||||||||
| namespace sidePanel { | ||||||||||||||
| dictionary CloseOptions { | ||||||||||||||
| // The window in which to close the side panel. | ||||||||||||||
| long? windowId; | ||||||||||||||
|
|
||||||||||||||
| // The tab for which to close the side panel. If specified, | ||||||||||||||
| // only closes tab-specific side panels. | ||||||||||||||
| long? tabId; | ||||||||||||||
|
|
||||||||||||||
| // At least one of these must be provided, otherwise rejects with an error. | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| interface Functions { | ||||||||||||||
| // Closes the extension's side panel. | ||||||||||||||
| // `options`: Specifies the context in which to close the side panel. | ||||||||||||||
| // `callback`: Called when the side panel has been closed. | ||||||||||||||
| static void close( | ||||||||||||||
| CloseOptions options, | ||||||||||||||
| optional VoidCallback callback); | ||||||||||||||
| }; | ||||||||||||||
| }; | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| ### Return value | ||||||||||||||
|
|
||||||||||||||
| - Type: Promise<void> | ||||||||||||||
|
|
||||||||||||||
| - Resolves when the panel has been closed. If the panel is | ||||||||||||||
| already closed, still resolves successfully. | ||||||||||||||
|
|
||||||||||||||
| ### Behavior | ||||||||||||||
|
|
||||||||||||||
| - The operation will only close side panels that belong to the | ||||||||||||||
| calling extension. | ||||||||||||||
| - If the panel is already closed or does not exist in the given | ||||||||||||||
| context, the method does nothing. | ||||||||||||||
| - If neither `windowId` nor `tabId` is provided, rejects with an error. | ||||||||||||||
| - If `windowId` or `tabId` is invalid, rejects with an error. | ||||||||||||||
| - If both `windowId` and `tabId` are provided, the method will verify | ||||||||||||||
| that the tab belongs to the specified window. If not, it rejects with an error. | ||||||||||||||
hharshas marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
| - If both `windowId` and `tabId` are provided: | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Calling only with a tabId should be possible |
||||||||||||||
| 1. If a contextual side panel is visible on the specified `tabId`, it will be closed. | ||||||||||||||
| 2. If a global side panel is visible on the given `tabId`, | ||||||||||||||
| it will be closed for all tabs in that window, not just the specified tab. | ||||||||||||||
|
Comment on lines
+96
to
+98
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| ### New Permissions | ||||||||||||||
|
|
||||||||||||||
| N/A | ||||||||||||||
|
|
||||||||||||||
| ### Manifest File Changes | ||||||||||||||
|
|
||||||||||||||
| N/A | ||||||||||||||
|
|
||||||||||||||
| ## Security and Privacy | ||||||||||||||
|
|
||||||||||||||
| ### Exposed Sensitive Data | ||||||||||||||
|
|
||||||||||||||
| This API does not expose any sensitive data. | ||||||||||||||
|
|
||||||||||||||
| ### Abuse Mitigations | ||||||||||||||
|
|
||||||||||||||
| The API is limited to closing only the extension's own side panel. | ||||||||||||||
|
|
||||||||||||||
| ### Additional Security Considerations | ||||||||||||||
|
|
||||||||||||||
| N/A | ||||||||||||||
|
|
||||||||||||||
| ## Alternatives | ||||||||||||||
|
|
||||||||||||||
| ### Existing Workarounds | ||||||||||||||
|
|
||||||||||||||
| * Message passing between background and panel contexts. | ||||||||||||||
| * Calling `window.close()` from the panel context. | ||||||||||||||
|
|
||||||||||||||
| ### Open Web API | ||||||||||||||
|
|
||||||||||||||
| Not applicable to the open web as it only complements the existing `open()` | ||||||||||||||
| functionality. | ||||||||||||||
|
|
||||||||||||||
| ## Implementation Notes | ||||||||||||||
|
|
||||||||||||||
| N/A | ||||||||||||||
|
|
||||||||||||||
| ## Future Work | ||||||||||||||
|
|
||||||||||||||
| This implementation will align with | ||||||||||||||
| [#779](https://github.com/w3c/webextensions/pull/779), to ensure proper event | ||||||||||||||
| handling on panel closure (Open for discussion). | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to the two different scenarios, in which the method is called with a
tabIdor without atabId