-
Notifications
You must be signed in to change notification settings - Fork 56
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
Ensure consistency of action.openPopup
API across browsers
#160
Comments
@zombie / @Rob--W, it would be great to get your input from the Mozilla side. @dotproto, I'm not sure if there's anything you can share on behalf of Google? Would you be open to discussions about using the same API namespace as Mozilla or is that off the cards given that you already use that namespace for an internal API? The crbug seems quiet unfortunately. |
We already added support for the
This seems reasonable, I filed Bug 1755763 to consider it. Another difference is that Chromium has an optional |
We (Apple) would implement the |
I want to track down why we the design doc mentions Links for later follow-up: crbug.com/1245093 |
I've been working on a Firefox patch to bring the behaviour closer to the Chromium implementation. Given this has shipped in Safari Technology Preview too, I wanted to investigate the behaviour in other browsers to make sure it was consistent. Sharing the results here for longevity...
¹ Notably windowId doesn't seem to be working in Chrome Canary (other than for already focused windows), which I'm fairly confident is a regression from when I last tested. There's already a comment about that and I've left another one. |
action.openPopup
APIaction.openPopup
API across browsers
Thanks for documenting the observed behavior @oliverdunk ! Here are some more interesting scenario's that aren't in the table yet:
|
@Rob--W: I went ahead and updated the table with those! Definitely some interesting results. |
Here is my proposed standard based on the behaviour which feels best in each case:
I've added "Behaviour when clicking browser icon would normally show permission prompt" for the following UI in Safari: The current Safari behaviour is to open the popup skipping this prompt (and not granting permissions), but I'm actually not sure if this is the way to go. Open to feedback there. |
I see potential for abuse here. I'd recommend to do nothing if no popup can be opened. |
Question: What happens / should happen if an extension calls |
In Chrome, this throws (with a no active window error if no I've updated the table of current behaviours and added a row in the proposed standard behaviours suggesting other popups are closed. I think this makes sense because stacking popups doesn't usually work well from a UX perspective and I think the fact that some browsers already close popups when the browser loses focus alleviates any data loss concerns. |
I think that we should throw if the offered/expected behavior is unclear. The When another extension has a popup open, we should throw IMO. When the extension already has a popup open, we could focus the popup if that makes sense. And perhaps also the window to which it is anchored. When a context menu or menu is open, it may be best to throw. Generally, if the user is clearly busy interacting with something, it may be a probably poor UX to interrupt them. |
@xeenon, would you mind sharing your thoughts here? |
What is the expected behaviour around popups receiving messages after being opened programmatically with this API ? As a developer, my understanding from https://stackoverflow.com/questions/48620183/chrome-extension-how-to-send-message-from-content-js-to-popup-js-page-action/ is that messages sent to a popup will only be received when a popup is open. I tested this behavior in Firefox (see code example from https://stackoverflow.com/questions/76709174/webextension-how-to-send-context-menu-selectiontext-to-popup-action) but it seems that the message is lost/not sent when the popup is active from I have a use case for this: a context menu extension that takes the textSelection, processes it through a function, and opens the extension popup to display the output (the alternative methods are displaying output in tab through |
I would absolutely expect the popup to receive messages as if it had been opened by the user. Could you try using setTimeout to delay sending the message, to see if it is a timing issue? I expect that to be the case, but if not, I would definitely open a Firefox bug. One thing we may want to discuss in the future is if openPopup should block on the popup loading. This seems desirable on first impressions but I actually think it's tricky - there are lots of edge cases if the popup closes before it loads, or an image takes a significant amount of time to load, where it's unclear at what point the promise should resolve. |
What's the point of having a Promise that doesn't await the task completely? This then leads into some terrible workarounds. I would say, at a very least, the initial JavaScript execution of the popup should be awaited, so that the popup is ready to receive messages. And if the popup is closed before it's loaded, the Promise can be rejected with some "loading interrupted" error. |
There are several examples of this, for example browser.tabs.create which can resolve before the tab has finished loading: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/create#return_value. I don't yet have a strong opinion on what the behaviour should be - but there are definitely tradeoffs. What if halfway through a script in the loading path of the popup, it makes a blocking XMLHTTPRequest call and hangs for a long period of time? I think in Chrome we actually delay the UI too, in which case delaying the API to match might make sense, but this definitely warrants some more investigation/discussion. |
I can only speak as a "user" of these API. And from that point of view, it's very convenient to open new window/tab/popup and send it some work/message/config. Let's compare it with some popular workarounds:
Maybe there is a better way? Alternatively, let's talk about the disadvantages. |
For sure, I completely understand! This is actually something I originally advocated for when we were working on I'm not saying I disagree with you on any of this. Just that there can be complexities, and we should discuss those within the group before deciding :) |
@Rob--W Currently Safari allows an extension to call openPopup() for a disabled popup. Firefox allows this, but it silently fails (regardless of the user gesture changes). I'm trying to decide on the behavior for Chrome to implement - any thoughts? My gut instinct is to allow this since there's no compelling reason not to and it may be useful in some cases. I don't feel too strongly though, and think ignoring and throwing an error would be another reasonable option. |
We've removed the channel restriction from I'm working on some follow-up improvements to error messages. I'm leaving the disabled popup behavior until we have consensus (currently, it rejects with an error). |
…h a call to `openPopup()`. https://webkit.org/b/275914 rdar://127836084 w3c/webextensions#160 Reviewed by Timothy Hatcher. Adds a static member to WebExtensionContext which signifies whether or not any extension has an open popup, along with other changes to WebExtensionContext to update this variable. * Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPIActionCocoa.mm: (WebKit::WebExtensionContext::actionOpenPopup): Modified to check the state of popupIsOpen * Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionActionCocoa.mm: (WebKit::WebExtensionAction::readyToPresentPopup): Modified to set the state of s_isPopupOpen when a popup is presented (WebKit::WebExtensionAction::closePopup): Modified to set the state of s_isPopupOpen when a popup is closed * Source/WebKit/UIProcess/Extensions/WebExtensionContext.h: (WebKit::WebExtensionContext::popupOpening): Setter for s_isPopupOpen (WebKit::WebExtensionContext::popupClosed): Setter for s_isPopupOpen (WebKit::WebExtensionContext::popupIsOpen const): Getter for s_isPopupOpen Canonical link: https://commits.webkit.org/280422@main
…h a call to `openPopup()`. https://webkit.org/b/275914 rdar://127836084 w3c/webextensions#160 Reviewed by Timothy Hatcher. Adds a static member to WebExtensionContext which signifies whether or not any extension has an open popup, along with other changes to WebExtensionContext to update this variable. * Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPIActionCocoa.mm: (WebKit::WebExtensionContext::actionOpenPopup): Modified to check the state of popupIsOpen * Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionActionCocoa.mm: (WebKit::WebExtensionAction::readyToPresentPopup): Modified to set the state of s_isPopupOpen when a popup is presented (WebKit::WebExtensionAction::closePopup): Modified to set the state of s_isPopupOpen when a popup is closed * Source/WebKit/UIProcess/Extensions/WebExtensionContext.h: (WebKit::WebExtensionContext::popupOpening): Setter for s_isPopupOpen (WebKit::WebExtensionContext::popupClosed): Setter for s_isPopupOpen (WebKit::WebExtensionContext::popupIsOpen const): Getter for s_isPopupOpen Canonical link: https://commits.webkit.org/280422@main
A Chromium bug was recently opened sharing an action.openPopup API, and a basic implementation has shipped restricted to the dev channel. This is super exciting since it's the first time Chrome extensions look set to get this ability.
Since Firefox has already implemented browserAction.openPopup, I'm curious on a few things:
browserAction.openPopup()
#15.ℹ️ Update: The initial questions here have been resolved and this issue is now tracking more nuanced behaviour differences between browsers. See the current behaviours and proposed standard behaviours.
The text was updated successfully, but these errors were encountered: