Skip to content

Commit

Permalink
Merge pull request #539 from appuio/polyfill-clone
Browse files Browse the repository at this point in the history
Add polyfill for structuredClone
  • Loading branch information
ccremer authored Apr 20, 2023
2 parents e5c8d49 + 06bb4dc commit 75f4c36
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,21 @@ import 'zone.js'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/

/**
* structuredClone is somewhat recent, thus maybe not available in all browsers.
*/
(function () {
if (typeof structuredClone !== 'undefined') {
return;
}
function structuredClone<T>(obj: T): T {
const jsonString = JSON.stringify(obj);
return JSON.parse(jsonString);
}
if (typeof window !== 'undefined') {
window.structuredClone = structuredClone;
} else {
throw new Error('Could not attach structuredClone polyfill to the window object');
}
})();

0 comments on commit 75f4c36

Please sign in to comment.