diff --git a/packages/near-membrane-dom/src/browser-realm.ts b/packages/near-membrane-dom/src/browser-realm.ts index e1544ea8..f69c419f 100644 --- a/packages/near-membrane-dom/src/browser-realm.ts +++ b/packages/near-membrane-dom/src/browser-realm.ts @@ -7,6 +7,7 @@ import { VirtualEnvironment, } from '@locker/near-membrane-base'; import { + isObject, ObjectAssign, ReflectApply, toSafeWeakMap, @@ -73,6 +74,7 @@ function createIframeVirtualEnvironment( } const { distortionCallback, + defaultPolicy, endowments, globalObjectShape, instrumentation, @@ -99,6 +101,12 @@ function createIframeVirtualEnvironment( blueConnector = createBlueConnector(globalObject); blueCreateHooksCallbackCache.set(blueRefs.document, blueConnector); } + // Install default TrustedTypes policy in the virtual environment. + // @ts-ignore trustedTypes does not exist on GlobalObject + if (typeof redWindow.trustedTypes !== 'undefined' && isObject(defaultPolicy)) { + // @ts-ignore trustedTypes does not exist on GlobalObject + redWindow.trustedTypes.createPolicy('default', defaultPolicy); + } const { eval: redIndirectEval } = redWindow; const env = new VirtualEnvironment({ blueConnector, diff --git a/packages/near-membrane-dom/src/types.ts b/packages/near-membrane-dom/src/types.ts index db3a23db..3ea73d70 100644 --- a/packages/near-membrane-dom/src/types.ts +++ b/packages/near-membrane-dom/src/types.ts @@ -7,6 +7,7 @@ import type { export interface BrowserEnvironmentOptions { distortionCallback?: DistortionCallback; + defaultPolicy?: object; endowments?: PropertyDescriptorMap; globalObjectShape?: object; instrumentation?: Instrumentation;