-
Notifications
You must be signed in to change notification settings - Fork 23
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
#7228: chrome.sidePanel
POC
#7232
Conversation
What do you mean by "I don't think it's a good time to explore this API"? Do you mean the
Correct. We're assembling that here (main discussion in Phase 1): https://www.notion.so/pixiebrix/Use-Chromium-Side-Panel-for-Sidebar-985eedfb2d62450584c2d03cab7bfb12?pvs=4
This is an area I want to dig into. From your investigation, it sounds like there's a single sidebar instance shared across tabs. It would be good to know what the tabId does? It might not link but instead indicate where it would show up? I will look at how Chrome's built-in sidebars handle tab change UX. For example, they have a shopping assistance sidebar that I'm curious how it handles changing product tabs vs. going to a tab where no product is located
I agree for MV3 it's not worth the two methods co-exist A gotcha is that mod-variables and mod state are tried to the content script. (See consideration writeup here: https://www.notion.so/pixiebrix/Phase-1-PixieBrix-sidebar-in-Chromium-Side-Panel-d95485473005421db945142bfa792568?pvs=4). If the sidebar is global, we can still just have it re-render whenever the focused tab changes to keep the content in sync with the page
There's probably a race condition with the controller on the page, or which content script gets to message it?
I'll check out the PR this afternoon and have some more questions from that Some additional questions off the top of my head
|
This PR in the current state uses that parameter so you can try it as well. In short it doesn't seem to have any behavioral change whatsoever. What might change is that this link can be verified via I'll investigate further. But I still think that even the sidebar were to be actually associated to a tab, it would have to unload/load at every tab switch.
I assume that the sidebar frame has a SPA and a
It doesn't look like it:
There's a small chance that the icon follows the browseAction's, but I doubt it. |
I have some good news. I created a standalone extension for ease of testing, and indeed:
This simplifies things greatly. Now the two major differences left are:
Next tasks:
Questions:
DemoThe code for this is: chrome.tabs.onUpdated.addListener(async (tabId, info, tab) => {
if (!tab.url) return;
await chrome.sidePanel.setOptions({
tabId,
path: 'sidepanel.html?tabId=' + tabId,
enabled: true
});
}); Screen.Recording.3.mov |
I pushed a commit which:
Things I've confirmed
New Questions (see comments in code)
I've implemented a POC of https://stackoverflow.com/a/77106777/402560 which seems to work for the 1 tab case for using the browser action button. It also uses the Page Visibility API to determine when the user has switched to a different panel in the sidebar. Working:
Still Broken:
|
@fregante what's an ETA on looking into the messenger to the sidebar? It seems to be working when going in the opposite direction (sidebar to content script). Probably a matter of fixing the target to no depend on tabId, but instead to pass the tabId via the page?:
|
@@ -52,6 +52,12 @@ function updateManifestToV3(manifestV2) { | |||
manifest.permissions = [...permissions, "scripting"]; | |||
manifest.host_permissions = origins; | |||
|
|||
// Add sidePanel | |||
manifest.permissions.push("sidePanel"); | |||
manifest.side_panel = { |
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.
TODO: need a "generic" sidebar that indicates it can only be used in the context of a web page tab?
Testing out the current solution, I added the "default" page to the manifest just help see issues better. I see one with the current logic: the sidebar does update with the correct URL on tab change (sidebar.html?tab=123) Screen.Recording.mov |
The new commit:
Remaining Work
|
/** | ||
* The Chrome Side Panel API doesn't have a method yet for checking if the sidebar is open, so track it ourselves. | ||
* @see init | ||
*/ | ||
let sidePanelOpen = false; |
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.
What happens when the page reloads and this data is lost? sidePanelOpen
is false but the sidebar is open.
In #7266 I'm currently just pinging the sidebar itself to check if it responds. It works 100% of the times, but we can verify later whether their callers actually need to have this information the same way.
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.
What happens when the page reloads and this data is lost? sidePanelOpen is false but the sidebar is open.
I believe the sidebar should reconnect after navigation (because the port would disconnect on navigation):
tabPort.onDisconnect.addListener(() => { |
Closing in favor of: #7320 |
Findings:
tabId
, that does not seem to make any difference (at least not automatically)Thoughts:
This PR accomplishes:
chrome.sidePanel.open(specific tab ID)
. There is no.close()
API but there might be other hackyish solutions.sidebar.html
to be associated with a specifictabId
, which may not be possible.Demos
Next
Any other questions you'd like answered? Want me to work on this further? The message