Repository navigation
Conversation
At init the library scanned every <script> named embed.js or iframely.js and took the CDN host from any of them at the root of its host, and the settings from the first one with a query string. Instagram, TikTok and Threads serve their own embed.js from the root of their hosts, so on a page with their embeds plain links could unfurl to //www.tiktok.com/api/iframe, and another provider's query string could replace the page's settings. The running tag is now found with document.currentScript. The CDN host comes only from that tag or from explicit configuration. Settings are read from that tag; other tags are scanned only when it has none (or the library runs without a tag of its own, as the ES module does), which keeps pages working where the query-less cloud copy from API embed codes boots first and another tag carries the key.
demo/other-embed-js.html loads a TikTok and an Instagram embed.js, and a made-up widget's embed.js with a query string, around our own tag. The test checks in three browsers that the running tag is found, its settings are the ones applied and plain links unfurl on the Iframely CDN. dist/ is rebuilt with the fix.
README and USAGE.md say that the script reads the tag that loaded it and that other files named embed.js on the page do not change its settings or CDN, and drop the advice to rename ours to iframely.js. They also say that the ES module and a bundled script need the CDN set in code. The changelog gets an Unreleased entry with the fix, the workaround for 1.x and the one behaviour change for sites on their own CDN.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
At start, embed.js read every
<script>namedembed.jsoriframely.json the page. It took the CDN host fromany of them served from the root of a host, and its settings from the first one with a query string.
Instagram and TikTok embed codes load their own
embed.jsfrom the root of their hosts. On a page with such anembed:
//www.tiktok.com/api/iframe?...and stay empty;embed.js?...could replace the page's settings, the key included.A
//cdn.iframe.ly/embed.js?key=...tag was not affected. A self-hosted script in a folder, a pre-set config with atag that has no query string, a bundled script and the ES module were. The bug dates from 1.x.
Fix
The script finds the tag that loaded it with
document.currentScript.//YOUR_CDN/embed.js), or from?cdn=, the pre-set config,configure({ cdn })oriframely.CDN.embed.js/iframely.jstags are read only when it has none, so a page wherethe cloud copy from API embed codes starts first and another tag carries the key keeps working.
Behaviour change
The ES module and a bundled script have no tag of their own, so they keep the default CDN whatever tags are on the
page. A site on its own CDN that relied on a
//YOUR_CDN/embed.jstag to tell them must setcdnexplicitly. Thesame goes for a self-hosted script in a folder (
?cdn=YOUR_CDN).Tests
demo/other-embed-js.html, in Chromium, Firefox and WebKit.