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

Explain choice of persistent or non-persistent content script #19711

Open
rebloor opened this issue Aug 18, 2022 · 1 comment
Open

Explain choice of persistent or non-persistent content script #19711

rebloor opened this issue Aug 18, 2022 · 1 comment
Labels
Content:WebExt WebExtensions docs p3 We don't have visibility when this will be addressed.

Comments

@rebloor
Copy link
Contributor

rebloor commented Aug 18, 2022

MDN URL

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts

What specific section or headline is this issue about?

No response

What information was incorrect, unhelpful, or incomplete?

Support for persistAcrossSessions in scripting.RegisteredContentScript was added and documented in Support for persistAcrossSessions #19196. However, this change didn't explain why developer might choose between persistent and non-persistent.

Notes for consideration:

Persistent is the default because the idea behind this API is that it's the dynamic version of the content_scripts key in manifest.json. Both registrations result in script executions at predictable* times, with the difference being that the new API allows an extension to dynamically (un)register scripts.

  • predictable as in runAt: "document_start" being respected; in contrast, when the (MV2-only) tabs.executeScript is used, the execution time is not guaranteed (hence the replacement of runAt with the injectImmediately option in the new scripting.executeScript API).

There are extensions that would like to have the script execution capabilities of registered content scripts, but not necessarily the persistent part of it. For example, if an extension (on behalf of a user) temporarily activated a content script with the goal of running it for content in the current session only. While it's not possible to restrict the registered content script to a specific tab, it is the closest that an extension can have if their goal is to schedule a content script for execution at the next load.

Although the specific topic is not clearly covered, this API design doc from Chrome may be helpful:
https://docs.google.com/document/d/1nRJ6iW-W1MVSpJnQzNrRQFLMsr0RycwsNym06TD5i18/edit

What did you expect to see?

Description of when to choose non-persistent over persistent.

Do you have any supporting links, references, or citations?

No response

Do you have anything more you want to share?

No response

@github-actions github-actions bot added needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. Content:WebExt WebExtensions docs labels Aug 18, 2022
@rebloor rebloor added p3 We don't have visibility when this will be addressed. and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Aug 18, 2022
@Hellx2
Copy link

Hellx2 commented Sep 9, 2022

You should choose non-persistent for things that won't save over sessions, for example, counters. With a counter for a user on a website, if you want it to start at zero then it should just have a value of zero and not be persistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebExt WebExtensions docs p3 We don't have visibility when this will be addressed.
Projects
None yet
Development

No branches or pull requests

2 participants