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

API to invalidate BFCache'd webpage with outdated content added by the extension #747

Closed
tophf opened this issue Jan 14, 2025 · 4 comments
Closed
Labels
opposed: chrome Opposed by Chrome opposed: firefox Opposed by Firefox opposed: safari Opposed by Safari

Comments

@tophf
Copy link

tophf commented Jan 14, 2025

Problem:

  1. Use an extension that modifies DOM of webpages e.g. applies themes (dark mode), adds DOM stuff like toolbars, etc.
  2. Navigate to another page, so the modified one goes into bfcache
  3. Change an option in the extension that substantially alters the way it affects DOM
  4. Go back to the bfcache'd page and observe the completely wrong content/appearance.

If we try to use a listener on pageshow event and retrieve the configuration, there'll be a noticeable delay before the up-to-date configuration is applied, which is very jarring when the visual changes are substantial.

Possible solution:

chrome.tabs.invalidateBFCache(tabId); // all cached documents
chrome.tabs.invalidateBFCache(tabId, {documentId: '...........'}); // just one

Alternatives:

chrome.tabs.update(tabId, {removeBFCache: true});
chrome.tabs.update(tabId, {removeBFCache: documentId1});
chrome.tabs.update(tabId, {removeBFCache: [documentId1, document2]});
@github-actions github-actions bot added needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: firefox Firefox needs to assess this issue for the first time needs-triage: safari Safari needs to assess this issue for the first time labels Jan 14, 2025
@tophf
Copy link
Author

tophf commented Jan 15, 2025

A potentially [much] simpler and cleaner solution might be to allow chrome.scripting.executeScript on a bfcached documentId so it will run when the document is restored:

chrome.scripting.executeScript({
  target: {tabId, documentIds: ['.........']},
  func: config => {/* apply config to the page */},
  args: [config],
});

Right now it ignores documentIds and just runs in the current document of the tab.

@dotproto
Copy link
Member

Note from today's meeting WECG meeting: using extension messaging to post a message to a BFCached document used to evict a document, but doesn't any more.

@xeenon xeenon added opposed: safari Opposed by Safari and removed needs-triage: safari Safari needs to assess this issue for the first time labels Jan 16, 2025
@Rob--W Rob--W added opposed: chrome Opposed by Chrome opposed: firefox Opposed by Firefox and removed needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: firefox Firefox needs to assess this issue for the first time labels Jan 16, 2025
@Rob--W
Copy link
Member

Rob--W commented Jan 16, 2025

The general consensus is to not introduce APIs to enable extensions to blanket evict bfcache'd contexts (meeting notes pending review at #750).

Instead, the idea is that the pageshow event is thought to be the right API, and that the problem of latency could be addressed by introducing an API to update values that can be retrieved synchronously from the content script. That topic has been discussed many times before, and #536 is one of the issues related to it.

@tophf
Copy link
Author

tophf commented Jan 16, 2025

Indeed, config registration would help, I totally forgot about it. I vaguely remember now it was about to be implemented 5+ years ago in Chrome.

@tophf tophf closed this as not planned Won't fix, can't repro, duplicate, stale Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
opposed: chrome Opposed by Chrome opposed: firefox Opposed by Firefox opposed: safari Opposed by Safari
Projects
None yet
Development

No branches or pull requests

4 participants