Skip to content

Commit b5c9917

Browse files
committed
fix(runtime): use document.defaultView to get real window object to solve csp issue
1 parent f779188 commit b5c9917

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

.changeset/cyan-emus-prove.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/runtime': patch
3+
---
4+
5+
fix(runtime): use document.defaultView to get real window object to solve csp issue

packages/runtime/src/global.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ export interface Federation {
2828

2929
export const nativeGlobal: typeof global = (() => {
3030
try {
31-
return new Function('return this')();
31+
// get real window (incase of sandbox)
32+
return document.defaultView;
3233
} catch {
34+
// node env
3335
return globalThis;
3436
}
3537
})() as typeof global;

0 commit comments

Comments
 (0)