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

Fix embeds in Chrome #384

Merged
merged 8 commits into from
Mar 20, 2024
Merged

Fix embeds in Chrome #384

merged 8 commits into from
Mar 20, 2024

Conversation

swissspidy
Copy link
Owner

@swissspidy swissspidy commented Mar 17, 2024

See #383 — this only fixes YouTube embeds but not Twitter embeds for example

Props @adamziel for the hint

Updates the MutationObserver instance to work inside the editor-canvas__iframe iframe and apply attributes to the .components-sandbox iframe as well.

Attributes do not need to be added to the YouTube iframe itself apparently.

All I had to do was ensure the .components-sandbox iframe has a src attribute set, even if it's empty.

To-do:

  • Add tests

Demo:

Screenshot 2024-03-17 at 19 53 50

Copy link

github-actions bot commented Mar 17, 2024

Size Change: +147 B (0%)

Total Size: 3.04 MB

Filename Size Change
build/media-experiments.js 64.3 kB +147 B (0%)
ℹ️ View Unchanged
Filename Size
build/100.js 83 kB
build/534.js 7.54 kB
build/699.js 2.36 MB
build/blurhash.worker.js 3.19 kB
build/canvas.worker.js 2.77 kB
build/chunk-ffmpeg.js 5.9 kB
build/chunk-selfie-segmentation.js 16.3 kB
build/dominant-color.worker.js 4.46 kB
build/ffmpeg.js 1.1 kB
build/heif.worker.js 424 kB
build/media-experiments-blocks-rtl.css 298 B
build/media-experiments-blocks.css 297 B
build/media-experiments-rtl.css 764 B
build/media-experiments.css 765 B
build/pdf.js 564 B
build/subtitles.js 864 B
build/upload-requests-modal-rtl.css 267 B
build/upload-requests-modal.css 268 B
build/upload-requests-modal.js 801 B
build/view-upload-request-view-rtl.css 714 B
build/view-upload-request-view.css 716 B
build/view-upload-request.js 16.8 kB
build/vips.worker.js 42.1 kB

compressed-size-action

@swissspidy
Copy link
Owner Author

Unfortunately Twitter embeds don't work yet, https://platform.twitter.com/widgets.js doesn't send the necessary headers to work with cross-origin isolation.

net::ERR_BLOCKED_BY_RESPONSE.NotSameOriginAfterDefaultedToSameOriginByCoep

@swissspidy
Copy link
Owner Author

swissspidy commented Mar 18, 2024

Explanation from the Chrome issues tab:

Because your site has the Cross-Origin Embedder Policy (COEP) enabled, each resource must specify a suitable Cross-Origin Resource Policy (CORP). This behavior prevents a document from loading cross-origin resources which don’t > explicitly grant permission to be loaded.

To solve this, add the following to the resource’ response header:

  • Cross-Origin-Resource-Policy: same-site if the resource and your site are served from the same site.
  • Cross-Origin-Resource-Policy: cross-origin if the resource is served from another location than your website.
    ⚠️ If you set this header, any website can embed this resource.

Alternatively, the document can use the variant: Cross-Origin-Embedder-Policy: credentialless instead of require-corp. It allows loading the resource, despite the missing CORP header, at the cost of requesting it without credentials like Cookies.

Cross-Origin-Embedder-Policy: credentialless is interesting as it's at least supported by Firefox and Chrome.

Unfortunately it does not make the Twitter embed work. widgets.js will be loaded, but after that it seems to silently fail.
In the DOM somewhere it says "platform.twitter.com refused to connect.

There is this https://platform.twitter.com/widgets/widget_iframe.2f70fb173b9000da126c79afe2098f02.html?origin=https%3A%2F%2Fmexp.local iframe that is not loading. Weirdly with the same recommendation about Cross-Origin-Embedder-Policy: credentialless despite that being set.

@swissspidy
Copy link
Owner Author

WICG/anonymous-iframe#14 gave me the right idea:

The sandbox iframe should be credentialless, but the tweet script itself should not be modified.

Tweet embeds are working now!

@swissspidy
Copy link
Owner Author

Just to clarify: this is only for Chrome and browsers that support credentialless, so the twitter embed is still broken in Safari and Firefox.

See https://developer.chrome.com/blog/iframe-credentialless

@swissspidy swissspidy changed the title Fix MutationObserver for nested iframes (embeds) Fix embeds in Chrome Mar 19, 2024
@swissspidy swissspidy merged commit 7090c48 into main Mar 20, 2024
15 checks passed
@swissspidy swissspidy deleted the fix/383-fix-embeds branch March 20, 2024 11:45
@adamziel
Copy link

Good explorations here @swissspidy! TIL about Cross-Origin-Embedder-Policy: credentialless. It seems like the cross origin separation is still settling down – I wonder how these platforms will adjust their embeds over time.

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