Hi Devlin,
this CL implements support for passing extension alarm name via `AlarmCreateInfo.name`. This is purely syntactic sugar to make the `alarms.create()` API a bit more ergonomic. After this CL, the following two calls are equivalent:
```js
alarms.create("kettle", {delayInMinutes: 1.5});
alarms.create({name: "kettle", delayInMinutes: 1.5});
```
This does not expose any new capabilities or behaviors, it merely scratches a long-standing itch I had.
We shortly discussed this at WECG and everyone expressed lukewarm interest in it:
https://github.com/w3c/webextensions/issues/999
https://github.com/w3c/webextensions/blob/main/_minutes/2026-05-21-wecg.md
Thanks!
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Thanks, Anton!
I'm not opposed to this, but I would like Oliver to weigh in from a devrel side. I agree this is the cleaner signature, but I could see an argument that having two supported signatures for the same effect is more confusing than having a single, well-documented, slightly-worse signature.
void ExtensionAlarmsTestGetNamedAlarmCallback(ExtensionAlarmsTest* test,nit1: Passing the test object here is a little unconventional. Two other options would be:
1) Using an instance method on the test itself, or
2) Using a lambda in the test.
That said, see below for what IMO is an even better solution.
base::BindOnce(ExtensionAlarmsTestGetNamedAlarmCallback, this));This won't work well in all cases -- tests don't run all pending callbacks, so when we reach the end of the test body, the test is done. This means that if this callback runs async, the test will finish, and the validation will never happen -- worse, we might potentially get a UAF, crashing the test suite.
I think we can make this much cleaner by using a base::test::TestFuture:
```
base::test::TestFuture<Alarm*> alarm_future;
alarm_manager_->GetAlarm(extension()->id(), "Alarm Name", alarm_future.GetCallback());
Alarm* alarm = alarm_future.Get();
// Verify alarm...
```
Under the hood, TestFuture::Get() will wait until the callback is invoked and return its resolved value.
"[\"Invalid\", {\"name\": \"Invalid\", \"delayInMinutes\": 0}]"));nit: cleaner to use a R"(String Literal)" here to avoid \\-escapes
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Hi Oliver, I would be glad to hear your thoughts regarding extend `alarms.create()` to also accept alarm name in the object. I believe it makes the API a bit more ergonomic. At the same time as Devlin noted, having two ways of doing something might be worse than just one not ergonomic way.
If Chromium and WECG/WEWG agrees that this is a valuable addition, I can prepare CLs/PRs implementing this for Chromium and Firefox and polyfil libraries of your choice. However, I can not say anything about the timelines for creating patches for multiple projects. Developing for Safari might be harder for me due to lack of a suitable compilation environment.
Hi Devlin, thanks for detailed feedback, I updated tests.
void ExtensionAlarmsTestGetNamedAlarmCallback(ExtensionAlarmsTest* test,nit1: Passing the test object here is a little unconventional. Two other options would be:
1) Using an instance method on the test itself, or
2) Using a lambda in the test.That said, see below for what IMO is an even better solution.
Done
base::BindOnce(ExtensionAlarmsTestGetNamedAlarmCallback, this));This won't work well in all cases -- tests don't run all pending callbacks, so when we reach the end of the test body, the test is done. This means that if this callback runs async, the test will finish, and the validation will never happen -- worse, we might potentially get a UAF, crashing the test suite.
I think we can make this much cleaner by using a base::test::TestFuture:
```
base::test::TestFuture<Alarm*> alarm_future;
alarm_manager_->GetAlarm(extension()->id(), "Alarm Name", alarm_future.GetCallback());
Alarm* alarm = alarm_future.Get();
// Verify alarm...
```Under the hood, TestFuture::Get() will wait until the callback is invoked and return its resolved value.
Done
"[\"Invalid\", {\"name\": \"Invalid\", \"delayInMinutes\": 0}]"));nit: cleaner to use a R"(String Literal)" here to avoid \\-escapes
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Hi Devlin,
this CL extends `alarms.create()` so that alarm name can be passed either as a separate (optional) first string parameter or within the object. For example, the following two calls will become equivalent:
```js
alarms.create("kettle", {delayInMinutes: 1.5});
alarms.create({name: "kettle", delayInMinutes: 1.5});
```
WECG discussed this proposal in detail and all three engines expressed support.[1]
What do you think of this CL?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Hi Justin,
this CL extends `alarms.create()` API so that the following two calls are equivalent:
```js
alarms.create("kettle", {delayInMinutes: 1.5});
alarms.create({name: "kettle", delayInMinutes: 1.5});
```
WECG/WEWG supports this API proposal (see links in the commit message).
Would you be interested in reviewing this? Thanks!
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
TEST_F(ExtensionAlarmsTest, CreateNameInObject) {Could you also create a simple WPT test for this new API surface? The existing alarm test suite it at: [//third_party/blink/web_tests/external/wpt/web-extensions/resources/alarms/background.js](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/web-extensions/resources/alarms/background.js).
I'd suggest a new test case called `testAlarmsCreateNames` and test:
1) the alarm name as a parameter
2) the alarm name in AlarmCreateInfo
3) not passing either (no alarm name parameter, but also not set in AlarmCreateInfo)
Use alarms.get() to verify that the alarm was created as expected, but we don't need to test that it actually fired (that's already tested in `testAlarmsOnAlarm`).
And then add to `testAlarmsErrorCases` a check for:
4) passing both, which throws an error
// MessageLoop when that happens.```suggestion
// `MessageLoop` when that happens.
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Hi Justin, please take another look. Thanks!
Could you also create a simple WPT test for this new API surface? The existing alarm test suite it at: [//third_party/blink/web_tests/external/wpt/web-extensions/resources/alarms/background.js](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/web-extensions/resources/alarms/background.js).
I'd suggest a new test case called `testAlarmsCreateNames` and test:
1) the alarm name as a parameter
2) the alarm name in AlarmCreateInfo
3) not passing either (no alarm name parameter, but also not set in AlarmCreateInfo)Use alarms.get() to verify that the alarm was created as expected, but we don't need to test that it actually fired (that's already tested in `testAlarmsOnAlarm`).
And then add to `testAlarmsErrorCases` a check for:
4) passing both, which throws an error
Thank you for clear request, I added these tests.
```suggestion
// `MessageLoop` when that happens.
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
lgtm, thanks Anton! Extra thanks for writing the WPT tests and fixing the existing .create() calls.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Hi Devlin, would you be interested in another round of reviews? Thanks!
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Exportable changes to web-platform-tests were detected in this CL and a pull request in the upstream repo has been made: https://github.com/web-platform-tests/wpt/pull/61508.
When this CL lands, the bot will automatically merge the PR on GitHub if the required GitHub checks pass; otherwise, ecosystem-infra@ team will triage the failures and may contact you.
WPT Export docs:
https://chromium.googlesource.com/chromium/src/+/main/docs/testing/web_platform_tests.md#Automatic-export-process
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
21 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
[Extensions] Implement AlarmCreateInfo.name
Add support for specifying alarm name for alarms.create() in the second
object argument called AlarmCreateInfo.name.
Background:
- https://github.com/w3c/webextensions/issues/999
- https://github.com/w3c/webextensions/blob/main/_minutes/2026-05-21-wecg.md
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
The WPT PR for this CL has been merged upstream! https://github.com/web-platform-tests/wpt/pull/61508
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |