-
Notifications
You must be signed in to change notification settings - Fork 69
Proposal: runtime.onInvalidated
event
#792
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
Merged
dotproto
merged 13 commits into
w3c:main
from
carlosjeurissen:proposal/runtime-onInvalidated
Jun 5, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dff9ba7
Add onInvalidated event proposal
carlosjeurissen 66ad36d
Update proposals/runtime_on_invalidated.md
carlosjeurissen a7bf013
Update OnInvalidatedReason to be consistent with tenses
carlosjeurissen bd3c64f
Make OnInvalidatedReason required
carlosjeurissen 8b0f67a
Use contexts terminology instead of frames and content scripts
carlosjeurissen 897c63e
Update contributors, fix proposal title
carlosjeurissen 76d5bd5
Drop Proposal Process description
carlosjeurissen 53c06f4
Update proposals/runtime_on_invalidated.md
carlosjeurissen 081132b
Update proposals/runtime_on_invalidated.md
carlosjeurissen e04d5bd
Update proposals/runtime_on_invalidated.md
carlosjeurissen 73d5243
Update proposals/runtime_on_invalidated.md
carlosjeurissen f7c7a22
Update setUninstalledURL comparison, add sensitive data info, fix lin…
carlosjeurissen 0de0941
Update contributors
carlosjeurissen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
# Proposal: browser.runtime.onInvalidated event | ||
|
||
**Summary** | ||
|
||
`browser.runtime.onInvalidated` | ||
|
||
This event notifies extension contexts that remain alive when the extension | ||
context gets invalidated. | ||
|
||
**Document Metadata** | ||
|
||
**Author:** carlosjeurissen | ||
|
||
**Sponsoring Browser:** Chrome | ||
|
||
**Contributors:** bershanskiy, xeenon, robwu | ||
|
||
**Created:** 2025-03-26 | ||
|
||
**Related Issues:** https://github.com/w3c/webextensions/issues/138 | ||
|
||
## Motivation | ||
|
||
### Objective | ||
|
||
This event notifies extension contexts that remain alive when the extension | ||
context gets invalidated. | ||
|
||
#### Use Cases | ||
|
||
When the extension context gets invalidated, this means extension contexts | ||
which stay alive can no longer use the extension APIs or communicate with other | ||
extension contexts. | ||
|
||
For extension contexts, knowing when this happens is crucial for moving | ||
forward. Alternatives can be used in this situation, like `window.open` instead | ||
of `browser.tabs.create`. If moving forward is no option, this event can be | ||
used for initiating the cleanup of any side effects caused in the frames | ||
extensions have been operating in. | ||
|
||
### Known Consumers | ||
|
||
Any extension with a content script which applies certain side effects to the | ||
web page. | ||
|
||
## Specification | ||
|
||
### Schema | ||
|
||
New onInvalidated event: | ||
```json | ||
{ | ||
"name": "onInvalidated", | ||
"type": "function", | ||
"description": "Fired when the extension context get invalidated while the underlying document remains valid.", | ||
"parameters": [ | ||
{ | ||
"type": "object", | ||
"name": "details", | ||
"properties": { | ||
"reason": { | ||
"$ref": "OnInvalidatedReason", | ||
"description": "The reason that this event is being dispatched." | ||
} | ||
} | ||
} | ||
] | ||
} | ||
``` | ||
|
||
The event should have a reason of type OnInvalidatedReason | ||
|
||
OnInvalidatedReason: | ||
|
||
```json | ||
{ | ||
"id": "OnInvalidatedReason", | ||
"type": "string", | ||
"enum": [ | ||
{"name": "uninstall", "description": "Specifies the event reason as an uninstallation."}, | ||
{"name": "update", "description": "Specifies the event reason as an extension update."}, | ||
{"name": "reload", "description": "Specifies the event reason as an extension reloading."}, | ||
{"name": "disable", "description": "Specifies the event reason as an extension disabling."} | ||
], | ||
"description": "The reason that this event is being dispatched." | ||
} | ||
``` | ||
|
||
### Behavior | ||
|
||
The event will be fired when the extension context get invalidated while the | ||
underlying document remains valid. The event only fires in extension contexts | ||
which are not already killed on invalidation. | ||
|
||
The event comes with a reason which specifies why an extension got invalidated. | ||
|
||
### New Permissions | ||
|
||
No new permissions introduced. | ||
|
||
### Manifest File Changes | ||
|
||
No new manifest fields. | ||
|
||
## Security and Privacy | ||
|
||
### Exposed Sensitive Data | ||
|
||
The event gives an invalidation reason. This could be used for gathering figures | ||
on extension updates and uninstalls. | ||
|
||
### Abuse Mitigations | ||
|
||
Currently extensions could try checking if an API gets thrown with an | ||
invalidated error. This would allow an extension to figure out if the extension | ||
is invalidated. No new abuse surface is introduced. | ||
|
||
As for the returned reason. The `uninstall` reason could potentially be used | ||
by extensions to modify every page to nag the user about reinstalling the | ||
extension. However extensions currently can already ask for this once by setting | ||
`browser.runtime.setUninstalledURL`. | ||
|
||
As for the `update` reason, this can be figured out by attempting to negotiate | ||
between the old content script and the new content script. | ||
|
||
The `disable` reason could provide additional information. However this seems | ||
to not be a big abuse surface. | ||
|
||
### Additional Security Considerations | ||
|
||
Extensions could potentially leak the onInvalidatedReason if they try hard. | ||
This does not seem to introduce any attack surfaces. | ||
|
||
## Alternatives | ||
|
||
### Existing Workarounds | ||
|
||
An extension could attempt to run an API which throws when an extension is | ||
invalidated. This is very expensive as it would require to run this API in a | ||
loop. In addition, the lack of an onInvalidated event leads to many | ||
extension developers to not deal with the situation in which the context is | ||
invalidated. Introducing the onInvalidated encourages developers to handle | ||
these situations. | ||
|
||
### Open Web API | ||
|
||
There is no viable path to turn this into an Open Web API. | ||
|
||
## Implementation Notes | ||
|
||
The event should be fired in the situation in which extension APIs would throw | ||
with an context invalidated error. | ||
|
||
## Future Work | ||
|
||
Not at this moment |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.