-
Notifications
You must be signed in to change notification settings - Fork 77
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
Open
hharshas
wants to merge
13
commits into
w3c:main
Choose a base branch
from
hharshas:sidepanel-close
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
37ea058
change: 1
6d34867
changes: 2
419caa5
changes: 3
f9b2fcb
changes : 4
96a097c
Trigger affiliation recheck
255679a
Re-Trigger affiliation recheck
e0db95e
Internal styling fixes
hharshas bbb14d3
trailing whitespace
hharshas 616013b
change in #use cases
hharshas 199ab84
Update #Behavior
hharshas 4eb6c07
Update #Objective
hharshas 5544257
Update sidepanel-close-api.md
hharshas 2ff64ff
Update #Behavior
hharshas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,136 @@ | ||||||||||
| # 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
|
||||||||||
|
|
||||||||||
|
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). | ||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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