Skip to content

Commit 7e295ab

Browse files
Add onInvalidated event proposal
1 parent b040a82 commit 7e295ab

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

proposals/runtime_on_invalidated.md

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Proposal: browser.runtime.onInvalidated event>
2+
3+
** How to Use This Template **
4+
5+
See [Proposal Process](proposal_process.md) for the detailed process on how to
6+
propose new APIs and use this template. Each section includes instructions on
7+
what to include. Delete the instructions for a given section once it's filled
8+
out. Remove this section once the template is filled out.
9+
10+
**Summary**
11+
12+
`browser.runtime.onInvalidated`
13+
14+
This event allows extension frames and content scripts to be notified when
15+
context get invalidated.
16+
17+
**Document Metadata**
18+
19+
**Author:** carlosjeurissen
20+
21+
**Sponsoring Browser:** Chrome
22+
23+
**Contributors:** TBD
24+
25+
**Created:** 2025-03-26
26+
27+
**Related Issues:** https://github.com/w3c/webextensions/issues/138
28+
29+
## Motivation
30+
31+
### Objective
32+
33+
This event allows extension frames and content scripts to be notified when
34+
context get invalidated.
35+
36+
#### Use Cases
37+
38+
Cleanup of effects in content scripts. After-invalidated handling of frames.
39+
For example, know when to use browser.tabs vs window.open.
40+
41+
### Known Consumers
42+
43+
Any extension with a content script which applies certain side effects to the
44+
web page.
45+
46+
## Specification
47+
48+
### Schema
49+
50+
New onInvalidated event:
51+
```json
52+
{
53+
"name": "onInvalidated",
54+
"type": "function",
55+
"description": "Fired when the extension context get invalidated.",
56+
"parameters": [
57+
{
58+
"type": "object",
59+
"name": "details",
60+
"properties": {
61+
"reason": {
62+
"optional": true,
63+
"$ref": "OnInvalidatedReason",
64+
"description": "The reason that this event is being dispatched."
65+
}
66+
}
67+
}
68+
]
69+
}
70+
```
71+
72+
Optionally gives a reason of type OnInvalidatedReason
73+
74+
OnInvalidatedReason:
75+
76+
```json
77+
{
78+
"id": "OnInvalidatedReason",
79+
"type": "string",
80+
"enum": [
81+
{"name": "uninstalled", "description": "Specifies the event reason as an uninstallation."},
82+
{"name": "update", "description": "Specifies the event reason as an extension update."},
83+
{"name": "reload", "description": "Specifies the event reason as an extension reloading."},
84+
{"name": "disabled", "description": "Specifies the event reason as an extension disabling."}
85+
],
86+
"description": "The reason that this event is being dispatched."
87+
}
88+
```
89+
90+
### Behavior
91+
92+
The event would be fired when the extension context get invalidated.
93+
Browsers can optionally pass a reason which allows an extension to determine
94+
the proper type of event.
95+
96+
### New Permissions
97+
98+
No new permissions introduced.
99+
100+
### Manifest File Changes
101+
102+
No new manifest fields.
103+
104+
## Security and Privacy
105+
106+
### Exposed Sensitive Data
107+
108+
Document any sensitive data or personally-identifiable information the API
109+
exposes to the extension.
110+
111+
### Abuse Mitigations
112+
113+
Currently extensions could try checking if an API gets thrown with an
114+
invalidated error. This would allow an extension to figure out if the extension
115+
is invalidated. No new abuse surface is introduced.
116+
117+
As for the returned reason. The uninstalled reason can not be abused more than
118+
currently `browser.runtime.setUninstalledURL`.
119+
120+
As for the `update` reason, this can be figured out by attempting to negotiate
121+
between the old content script and the new content script.
122+
123+
The `disabled` reason could provide additional information. However this seems
124+
to not be a big abuse surface.
125+
126+
### Additional Security Considerations
127+
128+
Extensions could potentially leak the onInvalidatedReason if they try hard.
129+
This does not seem to introduce any attack surfaces.
130+
131+
## Alternatives
132+
133+
### Existing Workarounds
134+
135+
An extension could attempt to run an API which throws when an extension is
136+
invalidated. This is very expensive as it would require to run this API in a
137+
loop. In addition, the lack of an onInvalidated event leads to many
138+
extension developers to not deal with the situation in which the context is
139+
invalidated. Introducing the onInvalidated encourages developers to handle
140+
these situations.
141+
142+
### Open Web API
143+
144+
There is no viable path to turn this into an Open Web API.
145+
146+
## Implementation Notes
147+
148+
The event should be fired in the situation in which extension APIs would throw
149+
with an context invalidated error.
150+
151+
## Future Work
152+
153+
Not at this moment

0 commit comments

Comments
 (0)