Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. SharedStorageRunOperation

SharedStorageRunOperation

Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.

TheSharedStorageRunOperation interface of theShared Storage API represents aRun output gate operation.

Instance methods

run()Experimental

Defines the structure to which therun() method defined inside a Run output gate operation should conform.

Examples

In this example, a class calledReachMeasurementOperation is defined in a worklet and is registered usingSharedStorageWorkletGlobalScope.register() with the namereach-measurement.SharedStorageRunOperation defines the structure to which this class must conform, essentially defining the parameters required for therun() method. Other than this requirement, the functionality of the class can be defined flexibly.

js
// reach-measurement-worklet.jsconst SCALE_FACTOR = 65536;function convertContentIdToBucket(contentId) {  return BigInt(contentId);}class ReachMeasurementOperation {  async run(data) {    const { contentId } = data;    // Read from Shared Storage    const key = "has-reported-content";    const hasReportedContent = (await this.sharedStorage.get(key)) === "true";    // Do not report if a report has been sent already    if (hasReportedContent) {      return;    }    // Generate the aggregation key and the aggregatable value    const bucket = convertContentIdToBucket(contentId);    const value = 1 * SCALE_FACTOR;    // Send an aggregatable report via the Private Aggregation API    privateAggregation.sendHistogramReport({ bucket, value });    // Set the report submission status flag    await this.sharedStorage.set(key, true);  }}// Register the operationregister("reach-measurement", ReachMeasurementOperation);

Note:It is possible to define and register multiple operations in the same shared storage worklet module script with different names. SeeSharedStorageOperation for an example.

In the main browsing context, thereach-measurement operation is invoked using theWindowSharedStorage.run() method:

js
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();

For more details about this example, seeUnique reach measurement. SeeShared Storage API for more examples.

Specifications

This feature does not appear to be defined in any specification.

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp