Fenced frames are intended to be used for cases such as displaying targeted ads selected via the Protected Audience API and WindowSharedStorage.selectURL()
. Communicating between <fencedframe>
s and other pages outside the <fencedframe>
on the page is intentionally limited, but one method of communication between the embedder and shared storage worklets does exist â FencedFrameConfig.setSharedStorageContext()
.
Note: Within the same <fencedframe>
tree, communication between frames is allowed. For example, a root <fencedframe>
can send a message to a child <iframe>
in its own tree, and a child <iframe>
can send a message to the parent <fencedframe>
.
Let's look at a more complex example that uses a Select URL output gate operation to render an ad in a <fencedframe>
.
In this example, a publisher asks a third-party content provider to render some content on the page. The content chosen with WindowSharedStorage.selectURL()
is rendered in a <fencedframe>
, and the content contains an <iframe>
from a measurement provider. Note that a publisher can represent any entity that is embedding a third-party <fencedframe>
. Also, a measurement provider represents any nested third-party code running in a <fencedframe>
of a different third party.
To pass data into a <fencedframe>
to be used in a shared storage worklet, the embedder can set the data in a FencedFrameConfig
. That value will be available as WorkletSharedStorage.context
inside the shared storage worklet. This data is not available outside a worklet, and can only be accessed inside a secure and private environment that a shared storage worklet provides.
When a selectURL()
call returns a FencedFrameConfig
, the frame embedder can pass in data by calling setSharedStorageContext(data)
:
const fencedFrameConfig = await window.sharedStorage.selectURL(
"creative-rotation",
urls,
{
// â¦
resolveToConfig: true,
},
);
fencedFrameConfig.setSharedStorageContext("some-data");
// Navigate the fenced frame to the config.
document.getElementById("my-fenced-frame").config = fencedFrameConfig;
setSharedStorageContext(data)
must be called on the fencedFrameConfig
before the intended <fencedframe>
element recipient has its config
attribute set to fencedFrameConfig
, as this triggers the frame to navigate.
Inside a shared storage worklet, WorkletSharedStorage.context
can then be accessed to retrieve the data:
class ReportingOperation {
async run() {
sharedStorage.set("some-data-from-embedder", sharedStorage.context);
}
}
register("send-report", ReportingOperation);
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4