Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples of using createWorklet #48

Merged
merged 2 commits into from
Oct 29, 2024
Merged

Add examples of using createWorklet #48

merged 2 commits into from
Oct 29, 2024

Conversation

taraojo
Copy link
Collaborator

@taraojo taraojo commented Aug 6, 2024

We want to show more uses of the createWorklet function, this PR adds 2 examples. The first being a straight swap from addModule to createWorklet within the iframe and the second using createWorklet with a cross-origin worklet without the iframe needed.

These changes are being added in relation to WICG/shared-storage#158.

@taraojo taraojo requested a review from kevinkiklee August 6, 2024 17:23
Copy link

github-actions bot commented Aug 6, 2024

@taraojo taraojo changed the title Add examples of using createWorklet [DNM] Add examples of using createWorklet Aug 12, 2024
We want to show more uses of the createWorklet method, this example is
a straight swap from addModule to createWorklet. In other examples I'll
remove the use of the iframe.
I've picked the creative rotation example at random to try out the
createWorklet function here. Unlike the previous commit where you
can do a straight swap between addModule and createWorklet, in this
commit I've removed the iframe completely. As we're relying on the
data being managed by the script-origin I've also had to move the
seedStorage function into the worklet so it is written into the
storage for the content producer instead of the publisher. I've
also set a new click handler for the demo controls, this also loads
the worklet to ensure we write to Shared Storage with the script-
origin.

Whenever we request a worklet from a different origin we need to
set the headers to allow cors and enable cross origin worklets. As
I've removed the iframe, I've moved the controls of the demo into
the invoking page directly (using hbs partials). For the sake of
the demo I've added the global getContentProducerUrl function to
make it easier to check the domain of the content producer within
the JS files for getting the worklet and the ads.

Also, as the demo is no longer being styled within the iframe I've
copied the css styles to the publisher pages.
@taraojo taraojo changed the title [DNM] Add examples of using createWorklet Add examples of using createWorklet Oct 29, 2024
@taraojo taraojo merged commit 3f194de into main Oct 29, 2024
5 checks passed
@taraojo taraojo deleted the createWorklet branch October 29, 2024 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants