web api instance method
WindowSharedStorage: run() method
The run() method of the
WindowSharedStorage interface executes a run operation that is registered in a module added to the current origin’s SharedStorageWorklet.
[!NOTE] The Run output gate is intended as a generic way to process some shared storage data.
Syntax
run(name)
run(name, options)
Parameters
name- : A string representing the registered operation’s name within the shared storage worklet module. It must match the name given to the operation when it is registered with
register().
- : A string representing the registered operation’s name within the shared storage worklet module. It must match the name given to the operation when it is registered with
optionsOptional- : An options object that can contain the following properties:
dataOptional- : An object representing any data required for executing the operation.
keepAliveOptional- : A boolean value. If set to
true, theSharedStorageWorkletGlobalScopeof the associated worklet is kept alive, and the operation can be run again. Therefore, you need to setkeepAlivetotruefor each operation that is not intended to be the last one. The default value,false, means that theSharedStorageWorkletGlobalScopeis terminated after the operation is run and cannot be run again.
- : A boolean value. If set to
- : An options object that can contain the following properties:
Return value
A Promise that fulfills with undefined.
Exceptions
TypeError- : Thrown if:
- The worklet module has not yet been added with
addModule(). - Shared storage is disabled (for example via a browser setting).
- The calling site does not have the Shared Storage API included in a successful privacy sandbox enrollment process.
- The worklet module has not yet been added with
- : Thrown if:
Examples
async function measureUniqueReach() {
// Load the Shared Storage worklet
await window.sharedStorage.worklet.addModule("reach-measurement-worklet.js");
// Run the reach measurement operation
await window.sharedStorage.run("reach-measurement", {
data: { contentId: "1234" },
});
}
measureUniqueReach();
See Unique reach measurement for a full explanation of this example. See Shared Storage API for more examples.
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.