Skip to content

Commit 966e02e

Browse files
authoredMar 18, 2025··
Use alarms to keep service worker running (#299)
Follow-up to #295, which doesn't seem to be enough to guarantee a good search experience the first time typing. This alarm approach seems to be not recommended, but it works well and can be limited to just run on Firefox where it's an issue. Without a much larger refactor or extensive testing, I think this is truly the best short term solution to using the extension on Firefox!
1 parent c9091e5 commit 966e02e

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed
 

‎extension/firefox-bg.html

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<meta charset="UTF-8" />
55
<title>Rust Search Extension</title>
66
<script src="service-worker.js" type="module"></script>
7+
<script src="service-worker-keepalive.js" type="module"></script>
78
</head>
89
<body></body>
910
</html>

‎extension/service-worker-keepalive.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* This is a hack to keep the service worker running forever on Firefox, which
3+
* aggressively shuts down the worker on Manifest v3 (resulting in a poor search experience).
4+
*
5+
* It may be possible to fine-tune the event registration so this isn't necessary,
6+
* but it seems like even re-initializing for omnibox.onInputStarted isn't enough to
7+
* get suggestions working how they used to in manifest v2.
8+
*
9+
* See <https://bugzilla.mozilla.org/show_bug.cgi?id=1771203> for more info.
10+
**/
11+
browser.alarms.onAlarm.addListener(() => {
12+
// This handler doesn't need to do anything, merely exist.
13+
});
14+
15+
// Default idle timeout is 30s, this alarm will fire every 20s
16+
browser.alarms.create("keepalive", { periodInMinutes: 1.0 / 3.0 });

‎manifest.jsonnet

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ json
4646
.addHostPermissions(host_permissions)
4747
.addOptionalHostPermissions(optional_host_permissions)
4848
.addIcons(icons())
49-
.addPermissions(['storage', 'unlimitedStorage'])
49+
.addPermissions(['storage', 'unlimitedStorage', 'alarms'])
5050
.setOptionsUi('manage/index.html')
5151
.addContentScript(
5252
matches=['*://docs.rs/*'],

0 commit comments

Comments
 (0)
Please sign in to comment.