Skip to content

Commit

Permalink
fix(runtime): use document.defaultView to get real window object to s…
Browse files Browse the repository at this point in the history
…olve csp issue (module-federation#3163)
  • Loading branch information
2heal1 authored Nov 5, 2024
1 parent 3942740 commit 54bfd1c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/cyan-emus-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/runtime': patch
---

fix(runtime): use document.defaultView to get real window object to solve csp issue
4 changes: 3 additions & 1 deletion packages/runtime/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ export interface Federation {

export const nativeGlobal: typeof global = (() => {
try {
return new Function('return this')();
// get real window (incase of sandbox)
return document.defaultView;
} catch {
// node env
return globalThis;
}
})() as typeof global;
Expand Down

0 comments on commit 54bfd1c

Please sign in to comment.