Problem with opening the sidepanel with shortcuts

156 views
Skip to first unread message

Guillaume Leon

unread,
Aug 30, 2023, 8:29:02 AM8/30/23
to Chromium Extensions
I'm currently developing an extensions based on the sidepanel, I want it to be convenient to open so I created a shortcut command inside my manifest.json

Except that when I execute my shortcut, an error occurs with sidepanel.open() telling me:

Error: `sidePanel.open()` may only be called in response to a user gesture.

I have trouble understand what is a user gesture, since a shortcut should be one ? 
Can anyone tell me if it's an intended behavior or if I'm missing anything (and maybe tell me if it's just not possible to do it through commands).

Oliver Dunk

unread,
Aug 30, 2023, 8:53:37 AM8/30/23
to Guillaume Leon, Chromium Extensions
Hi Guillaume,

Here's an example of an extension that opens the side panel with a shortcut (link).

If I had to guess, one possible issue is that you might not be calling sidePanel.open() in the same turn of the event loop. For example, if you await any promises or call open in a .then block, your user gesture will have expired by the time you call the API.

Let me know if this helps. If not, it'd be great to see your code.
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/d386d694-f595-40be-8db4-6a1f4258d928n%40chromium.org.

wOxxOm

unread,
Aug 30, 2023, 9:32:00 AM8/30/23
to Chromium Extensions, Oliver Dunk, Chromium Extensions, Guillaume Leon
I'd be good to have _execute_side_panel id in commands API so the extensions don't have to declare an otherwise unused service worker.

Guillaume Leon

unread,
Aug 30, 2023, 12:14:26 PM8/30/23
to Chromium Extensions, Oliver Dunk, Chromium Extensions, Guillaume Leon
Thanks a lot it works like a charm, I think this is some kind of weird behavior though, it would make sense that the command would keep their context 

Oliver Dunk

unread,
Aug 31, 2023, 6:48:59 AM8/31/23
to Guillaume Leon, Chromium Extensions
I'd be good to have _execute_side_panel id in commands API so the extensions don't have to declare an otherwise unused service worker.

Completely agree! I think that would be a good bug if there isn't one already.

I think this is some kind of weird behavior though, it would make sense that the command would keep their context 

I definitely agree that it can be confusing, and I think it's worth thinking about. That said, it can get really hard - if you call a function which then makes an external request that takes 30+ seconds to complete, that probably isn't reasonable to attach to the user gesture. So there's always a point where you have to draw the line, and that can be challenging - not to say that we shouldn't try to make it better :)
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB
Reply all
Reply to author
Forward
0 new messages