files/en-us/web/api/sharedstorageworkletglobalscope/register/index.md
{{APIRef("Shared Storage API")}}{{deprecated_header}}
The register() method of the
{{domxref("SharedStorageWorkletGlobalScope")}} interface registers an {{domxref("SharedStorageOperation", "operation", "", "nocode")}} defined inside the current worklet module.
register(name, operationCtor)
name
operationCtor
None (undefined).
operationCtor is not a valid constructor.run() method.// ab-testing-worklet.js
class SelectURLOperation {
async run(urls, data) {
// Read the user's experiment group from shared storage
const experimentGroup = await this.sharedStorage.get("ab-testing-group");
// Return the group number
return experimentGroup;
}
}
register("ab-testing", SelectURLOperation);
See the Shared Storage API landing page for a walkthrough of this example and for links to other examples.
[!NOTE] It is possible to define and register multiple operations in the same shared storage worklet module script with different names; see {{domxref("SharedStorageOperation")}} for an example.
{{Specifications}}
{{Compat}}