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

Fix #38690: Explain persistence of registered content scripts across browsers #38746

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mastaan66
Copy link
Contributor

Extended Commit Description

This update improves the documentation for the registerContentScripts method by explicitly clarifying the persistence behavior of registered content scripts across different browsers.

Changes made:

  • Added a Persistence of Registered Scripts section under Return Value to describe how long scripts remain registered in Firefox and Chrome.
  • Explained that in Firefox, registered scripts are removed when the extension is unloaded or reloaded.
  • Clarified that in Chrome, registered scripts persist across restarts if persistAcrossSessions: true, but are unregistered when the extension is updated.
  • Highlighted the role of the persistAcrossSessions property in controlling script persistence.

Why this change?

  • The previous documentation did not explicitly state how long registered scripts persist.
  • There was confusion regarding browser-specific behaviors, leading to inconsistencies in developer expectations.
  • Ensures that developers using the scripting.registerContentScripts API fully understand its behavior in both Firefox and Chrome.

This fix references MDN GitHub Issue #38690 and improves the clarity of the API documentation.


Description

This PR updates the registerContentScripts API documentation to clarify the persistence behavior of registered content scripts across different browsers. It explicitly explains how scripts behave in Firefox and Chrome, ensuring that developers are aware of browser-specific differences.


Motivation

  • Developers were unsure how long registered content scripts persist in different browsers.
  • Firefox and Chrome have different behaviors, which was not clearly mentioned.
  • The persistAcrossSessions property was not well-documented, especially regarding script removal during Chrome extension updates.
  • This change enhances developer clarity and avoids confusion when working with content scripts.

Additional Details


Related Issues and Pull Requests

### **Extended Commit Description:**  

This update improves the documentation for the `registerContentScripts` method by explicitly clarifying the persistence behavior of registered content scripts across different browsers.  

#### **Changes made:**  
- Added a **Persistence of Registered Scripts** section under **Return Value** to describe how long scripts remain registered in **Firefox** and **Chrome**.  
- Explained that in **Firefox**, registered scripts are **removed when the extension is unloaded or reloaded**.  
- Clarified that in **Chrome**, registered scripts **persist across restarts** if `persistAcrossSessions: true`, but **are unregistered when the extension is updated**.  
- Highlighted the role of the `persistAcrossSessions` property in controlling script persistence.  

#### **Why this change?**  
- The previous documentation did not explicitly state how long registered scripts persist.  
- There was confusion regarding **browser-specific behaviors**, leading to inconsistencies in developer expectations.  
- Ensures that developers using the `scripting.registerContentScripts` API fully understand its behavior in **both Firefox and Chrome**.  

This fix references [MDN GitHub Issue mdn#38690 ](mdn#38690) and improves the clarity of the API documentation.
@mastaan66 mastaan66 requested a review from a team as a code owner March 21, 2025 04:58
@mastaan66 mastaan66 requested review from rebloor and removed request for a team March 21, 2025 04:58
@github-actions github-actions bot added Content:WebExt WebExtensions docs size/s [PR only] 6-50 LoC changed labels Mar 21, 2025
Comment on lines 36 to 37
> [!NOTE]
> **Persistence of Registered Scripts:**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mdn-linter] reported by reviewdog 🐶

Suggested change
> [!NOTE]
> **Persistence of Registered Scripts:**
> [!NOTE] > **Persistence of Registered Scripts:**
>

Copy link
Contributor

github-actions bot commented Mar 21, 2025

Preview URLs

(comment last updated: 2025-03-21 19:17:04)

mastaan66 and others added 3 commits March 21, 2025 10:36
### **Extended Commit Description**  

This update fixes a syntax issue in the YAML front matter of the `index.md` file for `registerContentScripts`. The issue was caused by parentheses `()` in the `title` field, leading to a **SyntaxError: Unexpected token** during the CI checks.  

#### **Changes made:**  
- Removed parentheses `()` from the `title` field in the YAML front matter.  
- Updated the title from:  
  ```yaml
  title: scripting.registerContentScripts()
```
to
```yaml
title: scripting.registerContentScripts
```
### **Extended Commit Description**  

This update fixes **code style issues** in the `index.md` file by applying **Prettier formatting** to ensure compliance with MDN’s documentation standards. The CI checks failed due to **formatting inconsistencies**, and this commit resolves those issues.  

#### **Changes made:**  
- **Ran Prettier to format `index.md`** and fix all linting issues.  
- Ensured that the file follows **MDN’s code style guidelines**.  
- Addressed **all CI linting failures** that were blocking the PR merge.  

#### **Why this change?**  
- The CI logs indicated **formatting issues** in `index.md`:
@Juraj-Masiar
Copy link
Contributor

Thanks for the update!
But there is one issue, the persistAcrossSessions works now correctly also in Firefox, so the statement In Firefox, registered scripts are removed when the extension is unloaded or reloaded. is not fully correct and can be removed (the behavior was changing over the time).

And it seems that Firefox will also unregister the script after the extension update, same as Chrome.
So the second statement should be also updated, maybe say only:

Registered scripts persist across restarts if persistAcrossSessions: true, but they are unregistered when the extension is updated.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebExt WebExtensions docs size/s [PR only] 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing section about "persistance" of registerContentScripts
3 participants