Skip to content
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

Behaviour of extension message ports and bfcache #474

Open
oliverdunk opened this issue Oct 23, 2023 · 6 comments
Open

Behaviour of extension message ports and bfcache #474

oliverdunk opened this issue Oct 23, 2023 · 6 comments
Labels
follow-up: firefox Needs a response from a Firefox representative inconsistency Inconsistent behavior across browsers supportive: chrome Supportive from Chrome supportive: safari Supportive from Safari

Comments

@oliverdunk
Copy link
Member

Back/forward cache (bfcache) is an optimization in browsers where pages are suspended but cached upon navigation so that they can be more quickly restored if a user decides to return.

If a page that is entering the cache has an open message port to another part of the extension, it is unclear how this should be handled. For example, it could be kept alive with messages buffered, kept alive with messages dropped, or immediately closed. Alternatively, it could be dropped but only if a message is received.

We discussed this at TPAC and our current thinking is to immediately drop ports. This may require more work for some developers than alternatives, but is hopefully consistent behaviour that reduces the risk of extensions behaving in unexpected ways.

Opening this issue to track any further discussion and rollout.

@oliverdunk oliverdunk added inconsistency Inconsistent behavior across browsers supportive: chrome Supportive from Chrome supportive: safari Supportive from Safari follow-up: firefox Needs a response from a Firefox representative labels Oct 23, 2023
@oliverdunk
Copy link
Member Author

@zombie / @Rob--W: The conclusion we came to at TPAC was based on the understanding that the current Firefox behaviour is to immediately close ports. After some testing, however, it seems like the port actually remains open indefinitely and messages are dropped while the page is suspended. Does this match what you are seeing, and does it change your thoughts here?

@oliverdunk
Copy link
Member Author

We are moving forward with this change in Chrome: https://developer.chrome.com/blog/bfcache-extension-messaging-changes. Given the potential for breakage and the fact that this is not currently the behavior in Firefox, we are doing so cautiously and with warnings in DevTools to try and give time for extensions to adapt.

@xeenon
Copy link
Collaborator

xeenon commented Mar 3, 2024

WebKit issue tracking this: https://webkit.org/b/270413

@Jack-Works
Copy link

Currently, we're listening to port.onDisconnected to reconnect (not pageshow event). Will our code continue to work?

@oliverdunk
Copy link
Member Author

Currently, we're listening to port.onDisconnected to reconnect (not pageshow event). Will our code continue to work?

Good question! In Chrome, this depends on where you are listening to the event:

  • In the background context, the event does fire, including with a new error message starting in Chrome 124 (commit).
  • In the content script, we agreed with other browsers not to fire an event. There are some open questions around when that would fire and pageshow seemed to be a reasonable solution. If we see this causing issues longer term, it's something that we could discuss if we want to change.

@Jack-Works
Copy link

In the content script, we agreed with other browsers not to fire an event. There are some open questions around when that would fire and pageshow seemed to be a reasonable solution. If we see this causing issues longer term, it's something that we could discuss if we want to change.

So this means, my port will not receive a disconnect event and the next message cannot be sent? I don't think it's intuitive to developers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
follow-up: firefox Needs a response from a Firefox representative inconsistency Inconsistent behavior across browsers supportive: chrome Supportive from Chrome supportive: safari Supportive from Safari
Projects
None yet
Development

No branches or pull requests

3 participants