-
Notifications
You must be signed in to change notification settings - Fork 37
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
Investigate Embedding UI as Iframe #22
Comments
@ilyagelman @morsdyce Should work just fine, add this to any page to test (ES6 must be supported): /**
* Shredder API Dummy
*/
window.Shredder = {
sayHi: (one, two) => {
console.log('API sayHi', one, two);
}
};
/**
* Add an iFrame element for the Shredder UI
*/
let iframeElm = document.createElement('iframe');
iframeElm.src = '';
iframeElm.width = '100%';
iframeElm.height = '100%';
document.body.appendChild(iframeElm);
/**
* Get the iFrame's document, body and head
*/
let iframeRoot = iframeElm.contentDocument;
let iframeBody = iframeRoot.body || iframeRoot.querySelector('body');
let iframeHead = iframeRoot.querySelector('head') || iframeBody;
/**
* Prepare Shredder UI Styles
*/
let uiStyle = document.createElement('style');
uiStyle.textContent = `
h1 {
background: lightblue;
}
`;
/**
* Prepare Shredder UI View
*/
let uiHtml = document.createElement('div');
uiHtml.innerHTML = `
<div>
<h1>Bad Ass API Mocking</h1>
</div>
`;
/**
* Prepare Shredder UI Code
*/
let uiScript = document.createElement('script');
uiScript.type = 'text/javascript';
uiScript.text = `
// Execute methods from the Shredder API
window.parent.Shredder.sayHi('Foo', 'Bar')
`;
/**
* Inject the Shredder UI
*/
iframeBody.appendChild(uiHtml);
iframeHead.appendChild(uiStyle);
iframeBody.appendChild(uiScript); Open questions
|
@alexilyaev What about mocking xhr requests within iframe? |
@ilyagelman You don't, you mock them outside as usual, the iFrame is just the carrier that will communicate with the Shredder API. |
Maayan wrote:
|
+1 for including this here. On Wed, Dec 2, 2015 at 7:47 PM, Alex Ilyaev notifications@github.com
|
@ilyagelman Does it work with the 2 points Maayan mentioned? |
Investigate embedding the UI as an Iframe while still being able to communicate with the local API to capture requests and forward them to the UI.
The text was updated successfully, but these errors were encountered: