Skip to content

Commit

Permalink
fix(iframe-fixes): fix bug where removeNode fails due to not being pa…
Browse files Browse the repository at this point in the history
…tched like appendNode (#19)

Fixes #18
  • Loading branch information
silbinarywolf authored Nov 28, 2019
1 parent 5ab8a15 commit 348f275
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/iframe-fixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ function overrideSpecIFrameToApplyToAppIFrame(): void {
}
}

// Override document.removeChild on spec iframe so that if called it doesn't
// end up causing "The node to be removed is not a child of this node." errors.
{
const documentRemoveChild = function <T extends Node>(this: T): T {
return appDocument.appendChild.apply(appDocument, arguments as any) as T;
};
if (specDocument.removeChild !== documentRemoveChild) {
specDocument.removeChild = documentRemoveChild;
}
}

// Override document.body.appendChild on spec iframe so that we can append those
// elements to the app iframe.
{
Expand All @@ -54,6 +65,17 @@ function overrideSpecIFrameToApplyToAppIFrame(): void {
}
}

// Override document.body.removeChild on spec iframe so that if called it doesn't
// end up causing "The node to be removed is not a child of this node." errors.
{
const bodyRemoveChild = function <T extends Node>(this: T): T {
return appDocument.appendChild.apply(appDocument, arguments as any) as T;
};
if (specDocument.body.removeChild !== bodyRemoveChild) {
specDocument.body.removeChild = bodyRemoveChild;
}
}

// Override document.querySelector on spec iframe so that we can query for
// elements that have been rendered in the app iframe.
{
Expand Down

0 comments on commit 348f275

Please sign in to comment.