A simple TypeScript package to check whether a given URL can be embedded in an iframe based on its HTTP headers.
To install the package, run:
npm install iframe-visible
You can use the isEmbeddable
function to check if a URL is embeddable in an iframe. Here's how to use it:
import { isEmbeddable } from "iframe-visible";
const url = "https://example.com";
isEmbeddable(url)
.then((embeddable) => {
if (embeddable) {
console.log(`${url} can be embedded in an iframe.`);
} else {
console.log(`${url} cannot be embedded in an iframe.`);
}
})
.catch((error) => {
console.error("Error checking embeddability:", error);
});
using async, await
import { isEmbeddable } from "iframe-visible";
async function checkEmbeddability() {
const url = "https://example.com";
try {
const embeddable = await isEmbeddable(url);
if (embeddable) {
console.log(`${url} can be embedded in an iframe.`);
} else {
console.log(`${url} cannot be embedded in an iframe.`);
}
} catch (error) {
console.error("Error checking embeddability:", error);
}
}
checkEmbeddability();
- url: The URL to check.
- Returns a promise that resolves to
true
if the URL can be embedded in an iframe, andfalse
otherwise.
Feel free to submit issues or pull requests for improvements or bug fixes.
This project is licensed under the MIT License.