Skip to content

Complete guides and evals for three Cross-Origin Storage use cases - #1347

Open
tomayac wants to merge 6 commits into
mainfrom
guidance/cos-use-case-evals
Open

Complete guides and evals for three Cross-Origin Storage use cases#1347
tomayac wants to merge 6 commits into
mainfrom
guidance/cos-use-case-evals

Conversation

@tomayac

@tomayac tomayac commented Aug 17, 2026

Copy link
Copy Markdown
Member

Fills in the remaining required files for the three Cross-Origin Storage (COS) use case stubs that #1208 added: guide.md content, negative-demo.html, grader.ts, and tasks/task.md. Written against a fresh read of the WICG/cross-origin-storage README.

What's in this PR

  • avoid-redundant-large-asset-downloads covers the imperative navigator.crossOriginStorage.requestFileHandle() API: checking COS before a network fetch, treating NotFoundError as a cache miss, storing with create: true, and choosing an origins scope deliberately.
  • load-shared-resources-declaratively covers the declarative HTML crossoriginstorage attribute on <link>/<script> and the crossOriginStorage JS import attribute.
  • share-web-fonts-across-origins covers the declarative CSS cross-origin-storage() request-url-modifier used alongside integrity() in @font-face.

Each use case now has a guide.md with how-to-implement steps, example code, best practices, and a fallback strategy section; a negative-demo.html that omits COS entirely as the grading counterpart to the existing demo.html; a grader.ts with Playwright checks derived from expectations.md; and a tasks/task.md using the empty-app base app, matching the pattern used by the other resource-loading use cases in this repo.

Closes #1281
Closes #1282
Closes #1283

Opening as a draft so the grader assertions and task phrasing can get a look before merge.

@tomayac
tomayac marked this pull request as ready for review August 17, 2026 13:13
@micahjo7

Copy link
Copy Markdown
Collaborator

We've recently merged an update to the eval generation structure which deprecates the eval artifacts generated by gd dev in this PR (including demo.html, negative-demo.html, etc.).

Would you mind removing those generated artifacts from this PR, and we can re-generate with the new format in subsequent PRs? The process is documented in https://github.com/GoogleChrome/modern-web-guidance-src/blob/main/guides/README.md?plain=1#L14.

Fills in the remaining required files for the three Cross-Origin
Storage (COS) use case stubs added in #1208: guide.md content,
negative-demo.html, grader.ts, and tasks/task.md.

- avoid-redundant-large-asset-downloads: imperative
  navigator.crossOriginStorage.requestFileHandle() API.
- load-shared-resources-declaratively: declarative HTML
  crossoriginstorage attribute and JS crossOriginStorage import
  attribute.
- share-web-fonts-across-origins: declarative CSS
  cross-origin-storage() request-url-modifier.

Fixes #1281
Fixes #1282
Fixes #1283
The first task description mentioned an AI model, then referenced a
shared library. Rewrote all three task variations to consistently
describe loading the ffmpeg.wasm core module.
demo.html and guide.md called navigator.crossOriginStorage.requestFileHandle()
behind a supportsCOS existence check. Removed that check: the API is now
called directly and every outcome is handled with try/catch, matching the
COS explainer's own example code and the fact that a fully implemented
COS can still legitimately reject a call (availability gating, GREASE'ing,
Permissions Policy).

grader.ts previously replaced navigator.crossOriginStorage with a
hand-rolled in-memory mock. Removed the mock: the grader now assumes COS
is natively implemented in the test environment and only wraps the real
requestFileHandle() to record calls for assertions, forwarding every call
to the original implementation unchanged. Also aligned demo.html,
negative-demo.html, and grader.ts on the ffmpeg-core.wasm asset used in
tasks/task.md.
'Defensive' meant still wrapping calls in try/catch after a passed
feature-detection check, not skipping the check entirely. Restored the
single up-front navigator.crossOriginStorage?.requestFileHandle check
with immediate fallback to the network when absent, while keeping
try/catch around every COS call for outcomes a fully implemented COS
can still legitimately reject (availability gating, GREASE'ing,
Permissions Policy).

Updated guide.md, expectations.md, and grader.ts to match.
The hashes in demo.html/negative-demo.html were copied from the WICG
explainer's own illustrative placeholders (e.g. 8f434346..., sha256-abc123...)
and never corresponded to any actual bytes. Now that the graders assume a
real, non-mocked Cross-Origin Storage implementation, that's a functional
bug: a real implementation hash-verifies written bytes against the
declared hash and rejects a mismatch with a DataError, so the store step
would silently fail every time and the demos would never actually
exercise the cache-hit path.

Shipped small placeholder files alongside each demo and computed their
real SHA-256 digests:

- avoid-redundant-large-asset-downloads/assets/ffmpeg-core.wasm: a
  minimal stand-in for the real (multi-megabyte) ffmpeg.wasm core module.
  Shipping the actual production binary would add several MB to this PR
  for no grading benefit, so this is a small placeholder that starts with
  the real Wasm magic number, with the hex hash in demo.html updated to
  match.
- load-shared-resources-declaratively/assets/{shared-widget.css,
  shared-widget.js,shared-config.js}: small stand-ins for a popular
  stylesheet, script, and config module, with the SRI-style base64
  hashes in demo.html and negative-demo.html updated to match.
- share-web-fonts-across-origins/fonts/shared-emoji.woff2: a small
  stand-in for a popular emoji font, with the SRI-style base64 hash in
  demo.html updated to match.

Verified each shipped file's SHA-256 digest against the hash referenced
in its demo before committing. Also removed grader.ts's synthetic
fake-body fallback for ffmpeg-core.wasm, now dead code since the real
file is served from disk like every other asset.
The eval generation structure was recently updated, deprecating the eval
artifacts this PR generated. Drop them here so they can be regenerated in
the new targets/<base_app>/ format in follow-up PRs:

- grader.ts, negative-demo.html, and tasks/task.md for all three guides
- the asset fixtures that existed only to back them (ffmpeg-core.wasm,
  shared-{config.js,widget.css,widget.js}, shared-emoji.woff2)

demo.html is restored to its pre-PR state rather than deleted, since it
predates this PR and every other guide still ships one; removing it looks
like a repo-wide cleanup rather than this PR's job.

What remains is the guidance itself: guide.md for all three use cases,
plus one added expectation.

Also teach getStatusMessage() to report registered tmp-* feature IDs.
#1256 added tmp-* handling to validateFeature() and getFeatureName() but
not to this path, so BASELINE_STATUS("tmp-cross-origin-storage") in the
new guides threw "Status not found" and failed the guides integrity test.
Pending features now report as unsupported everywhere, with a link to the
upstream tracking issue.
@tomayac
tomayac force-pushed the guidance/cos-use-case-evals branch from 3832a86 to ea4b81c Compare August 18, 2026 11:53
@tomayac

tomayac commented Aug 18, 2026

Copy link
Copy Markdown
Member Author

Remove deprecated eval artifacts, keep guidance content

Thank you, done all of that in ea4b81c. PTAL.

@rviscomi rviscomi added the content Pertaining to what the guidance instructs label Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

content Pertaining to what the guidance instructs

Projects

None yet

3 participants