iframe-injectable documentation
Simple typescript function allowing one to inject into iframe any javascript, styles, css that is desired.
Example of use
import iframe from 'iframe-injectable';
const successDiv = document.createElement('div');
successDiv.setAttribute('name', 'success');
successDiv.appendChild(document.createTextNode('Success!'));
const successSpan = document.createElement('span');
successSpan.appendChild(document.createTextNode('Span success'));
const frame = iframe('#frame')
.dom(successDiv)
.dom(successSpan, '[name="success"]')
.style('body { background-color: pink; }')
.css('style.css')
.js((window, document) => {
console.log(window.innerWidth);
document.body.appendChild(document.createTextNode('Success!!'));
});
(async () => {
console.log((await frame.head())?.baseURI);
console.log((await frame.body())?.className);
console.log(await iframe(1).test());
})();
Addendum
This package may throw CORS errors if you try and edit an iframe which is from cross-domain without proper policy.
Changes since 0.1.0
Can now test CORS accessibility with .test() method, which returns a boolean promise
If you discover any bugs, or have ideas about improving this package, do not hesitate to file in an issue or create a pull request.