Skip to content

Enabling Client Side Media Processing in Gutenberg blows Playground #2954

Closed

Description

@SirLouen

Reproduction Steps:

  1. Enable the Gutenberg plugin
    https://playground.wordpress.net/?gutenberg-branch=trunk
  2. Go to Gutenberg > Experiments
  3. Enable Client-side media processing
  4. Add a New Post
  5. 💥

Activity

  1. changed the title [-]Enabling Client Side Media Processing blows Playground[/-] [+]Enabling Client Side Media Processing in Gutenberg blows Playground[/+] on Nov 27, 2025
  2. bph commented on Dec 2, 2025

    @bph
    Collaborator

    I can confirm. From the browser console screenshot, it might be a CORS issue or so.

    The Logs Tab doesn't reveal anything relevant. This is the only entry

    [02-Dec-2025 08:17:07 UTC] JavaScript warn: The "zipPath" option of the unzip() Blueprint step is deprecated and will be removed. Use "zipFile" instead.

    That's there too few, the browser console has too many entries.

    Image

    This is the screen I see:

    Image
  3. adamziel commented on Dec 2, 2025

    @adamziel
    Collaborator

    Client-side media processing uses SharedArrayBuffer which, in turn, requires cross-origin isolation via the Cross-Origin-Embedder-Policy (COEP) and Cross-Origin-Resource-Policy (CORP) headers. Those headers are viral-ish, and once a part of a site sets them, the rest of the site must follow. This is why YouTube embeds broke at one point when I was experimenting with these.

    I can see the following options:

    • Set the COEP/CORP headers only on the editor screens and only when media experiments are enabled – this will break embeds YouTube embeds, but only in the editor. That's consistent with what's likely happening in "native" WordPress and seems like a good option.
    • Set the COEP/CORP headers for the entire Playground – that's easier technically, but it will also break embeds such as YouTube site-wide so it's not a good option.
    • Don't support client-side media processing. That's not a good option, I'm only mentioning it for completeness.

    I wonder if there are other good options I'm missing here – cc @swissspidy @ramonjd @brandonpayton

  4. added
    [Type] Enhancement
    on Dec 2, 2025
  5. swissspidy commented on Dec 2, 2025

    @swissspidy
    Member

    Set the COEP/CORP headers only on the editor screens and only when media experiments are enabled

    This should already be the case in the current implementation in Gutenberg and in the Media Experiments plugin

  6. adamziel commented on Dec 2, 2025

    @adamziel
    Collaborator

    @swissspidy Oh, that's right!:

    add_action( 'load-post.php', 'gutenberg_set_up_cross_origin_isolation' );
    add_action( 'load-post-new.php', 'gutenberg_set_up_cross_origin_isolation' );
    add_action( 'load-site-editor.php', 'gutenberg_set_up_cross_origin_isolation' );
    add_action( 'load-widgets.php', 'gutenberg_set_up_cross_origin_isolation' );

    I somehow assumed the entire server configuration needs updating to serve all the CSS, JS, etc. assets with COEP/CORP headers, but it seems like doing it just for the editor page is enough?

    🤔

    The difficult part seems to be embedding WordPress in an iframe. I think Playground is blowing up because we are embedding an origin-isolated resource in a non-origin-isolated page. If that's correct, we'd need to serve these headers on the entire https://playground.wordpress.net/ – but that would affect the editor even when the media experiment is not enabled.

    Ideally, we'd be able to activate the origin-isolated mode when the editor demands it, and deactivate it once we navigate away from the isolated editor. However, I don't think we can switch between those modes without a full playground.wordpress.net reload. This means we need to either:

    • Stick to a non-isolated mode – and don't support client-side media processing
    • Stick to an isolated mode – and don't support embeds
    • Dynamically switch between the two modes – and make the user experience more rough, e.g. we may surprise the user with a sudden page reload, we'll likely lose some UI state, and we may also trigger the "are you sure you want to reload?" alert at times. We'll also need to save the temporary Playground in OPFS and restore it from there, which could take a few seconds and add to the roughness.

    I wonder if I'm missing a fourth solution here that would solve it without any big downsides. Maybe an explicit ?origin-isolation setting that must be present from the beginning of the Playground session?

  7. swissspidy commented on Dec 2, 2025

    @swissspidy
    Member

    You might want to check out Document Isolation Policy, which is supposed to supersede COEP/COOP and applies per frame. Chrome only now though at the moment. See https://developer.chrome.com/blog/document-isolation-policy

  8. JanJakes commented on Dec 11, 2025

    @JanJakes
    Member

    I asked Claude to investigate, summarize, and research the possible solutions for me, and it did an impressive job (see below).

    Then I went on to try Document Isolation Policy, and it appears to be working: #3020

    [Claude summary of the issue below]


    Root Cause

    When the "Client-side media processing" experiment is enabled in Gutenberg within WordPress Playground, the application crashes because:

    1. Gutenberg's media processing uses wasm-vips (image processing) and ffmpeg.wasm (video/audio processing)
    2. These WebAssembly libraries require SharedArrayBuffer for multi-threaded operations
    3. SharedArrayBuffer requires cross-origin isolation via COEP (Cross-Origin-Embedder-Policy) and CORP (Cross-Origin-Resource-Policy) headers
    4. Playground deliberately avoids these headers because they break iframe embedding and third-party embeds (YouTube, etc.)

    Assumptions Verified

    1. Playground explicitly avoids COEP/CORP headers

      Found in packages/php-wasm/universal/src/lib/comlink-sync.ts:22-26:

      * SharedArrayBuffer is an option, but it requires more restrictive CORP+COEP
      * headers which breaks, e.g., YouTube embeds.
    2. Service worker manipulates response headers but doesn't add cross-origin isolation

      In packages/php-wasm/web-service-worker/src/utils.ts, the service worker:

      • Removes x-frame-options to allow iframe embedding
      • Removes frame-ancestors from CSP to allow cross-origin embedding
      • Does NOT add COEP/COOP headers
    3. The iframe architecture is complex

      Playground uses nested iframes, and the Gutenberg site editor adds another level that Playground patches in service-worker.ts.

    4. Gutenberg does add headers when experiment is enabled (as @swissspidy mentioned)

      The problem is that these headers conflict with Playground's iframe embedding model.

    Solution Evaluation

    Option Complexity Viability Notes
    Set headers only on editor screens Very High Low Would require detecting when Gutenberg experiment is enabled. Embeds in editor would still break. Site editor iframe patching could break.
    Set headers site-wide Low Very Low Breaks ALL embeds everywhere (YouTube, Vimeo, Twitter, etc.). Not viable for a WordPress testing environment.
    Don't support (document limitation) None High Simple, honest approach. Document that this experiment is incompatible with Playground's architecture.
    Document Isolation Policy Medium Medium New Chrome feature (Chrome 137+) enables per-frame isolation without affecting child frames. Chrome desktop only.
    Hybrid approach Medium Best Use Document Isolation Policy when available, graceful degradation with informative message when not.

    Document Isolation Policy - A Potential Path Forward

    Document Isolation Policy is a new feature shipping in Chrome 137 (late 2025) that differs from COEP:

    • Applies per-frame, not site-wide
    • Doesn't require embedded iframes to support COEP
    • Documents can still open cross-origin popups and embed iframes normally
    • Header: Document-Isolation-Policy: isolate-and-credentialless

    Limitations:

    • Chrome 137+ desktop only (no Firefox, Safari, or mobile)
    • Isolated frames lose synchronous DOM access to same-origin non-isolated frames

    Recommendation

    Hybrid approach with clear documentation:

    1. Detect Document Isolation Policy support via feature detection
    2. When supported (Chrome 137+): Add Document-Isolation-Policy: isolate-and-credentialless header
    3. When not supported: Display a clear message explaining the limitation when the Gutenberg experiment is detected
    4. Document the limitation in Playground docs with browser compatibility info

    Alternatively, wait for broader browser support - Document Isolation Policy is very new. We could document the current limitation and implement when Firefox/Safari add support.

    References

  9. adamziel commented on Dec 12, 2025

    @adamziel
    Collaborator

    @JanJakes Oh! So it seems like using that header in Chrome 137+ would already improve the situation for some users? And perhaps we can even do it at a service worker level to swap the CORP/COEP headers for that one when we detect Chrome? Let's try that, it seems like a worthwhile plan.

  10. adamziel commented on Dec 12, 2025

    @adamziel
    Collaborator

    #3028 might fix it in Chrome

  11. adamziel commented on Dec 19, 2025

    @adamziel
    Collaborator

    With that PR merged and the editor no longer crashes on chrome. I still do not see the "media experiments" inspector controls from Pascal's post, but at least the editor canvas doesn't crash in Chrome. @swissspidy any idea what are we missing?

    Image

    As for Safari and Firefox, I don't think there's any viable solution we could roll out there (other than just waiting for them to implement the Document-Isolation-Policy specification). If anyone has any ideas, please share.

  12. swissspidy commented on Dec 19, 2025

    @swissspidy
    Member

    These controls are from https://github.com/swissspidy/media-experiments. Only very little of that plugin's functionality is in Gutenberg yet.

  13. adamsilverstein commented on Feb 26, 2026

    @adamsilverstein
    Member

    I am investigating a fix for this on the Gutenberg side in WordPress/gutenberg#75941. If we can't get this to work properly, I will try to disable in the Playground context.

  14. adamsilverstein commented on Feb 26, 2026

    @adamsilverstein
    Member

    #3028 might fix it in Chrome

    @adamziel how are you testing? how do i test GB trunk in playground?

    if you upload an image do you see a bunch of rest-api "sideload" requests?

    Image

    these are the resized images being uploaded to the server and indicate the feature is working correctly.

    If not, do you agree I should disable Client Side Media for Playground since it is no longer an experiment?

  15. adamziel commented on Feb 26, 2026

    @adamziel
    Collaborator

    @adamsilverstein I'm investigating, let's hold with making any changes – I'd like to understand what broke exactly so that we can prevent similar breakages in the future.

  16. adamziel commented on Feb 27, 2026

    @adamziel
    Collaborator

    @brandonpayton disabled the experiment in Playground for the time being to unlock using it with beta2. Meanwhile, I'm investigating what happened. This is pretty interesting:

    Image Image

    It seems like the Document-Isolation-Policy doesn't mix well with COEP. I wonder if we're doing that anywhere or if anything changed about the way WordPress serves these headers.

  17. adamziel commented on Feb 27, 2026

    @adamziel
    Collaborator

    #3320 explores the root causes of the problem, which seems to be at the intersection of some DIP nuances and the recent changes in the block editor. I wonder if there’s even a good solution to this given that DIP may not be coming to mobile which means WordPress Core doesn’t have a good incentive to adopt it as that would require maintaining both CORP/COEP and DIP. 🤔

    Also, related WebKit issue about DIP: WebKit/standards-positions#399

  18. adamziel commented on Mar 12, 2026

    @adamziel
    Collaborator

    With WordPress/gutenberg#75991 merged, we can probably remove all the DIP-related code from Playground and just let WordPress do its thing, at least if that PR is getting released with 7.0.

    Edit: It is! WordPress/wordpress-develop#11098

  19. fellyph commented on Nov 17, 2026

    @fellyph
    Collaborator

    Closing as resolved by #3515, tracked to completion in #3514. The E2E tests cover the editor and media-processing feature on Chromium. Firefox and Safari use a fallback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions