1 /** We're using a Proxy here to avoid loading the UI WASM file in
2 * contexts where it should not live. This ensures that the PassUI
3 * module is not executed in workers or content-scripts */
4 import type PassRustUI from '@protontech/pass-rust-core/ui';
6 import { isNativeJSError } from '@proton/pass/lib/core/utils';
7 import type { Maybe } from '@proton/pass/types';
8 import { logger } from '@proton/pass/utils/logger';
10 type PassUI = typeof PassRustUI;
11 let service: Maybe<PassUI>;
13 export const preloadPassCoreUI = () => {
14 if (service !== undefined || typeof window === 'undefined') return;
15 return import(/* webpackChunkName: "pass-core.ui" */ '@protontech/pass-rust-core/ui')
18 logger.debug(`[PassCoreUI] Module v${value.library_version()} loaded`);
20 .catch((err) => logger.warn('[PassCoreUI] Failed loading module', err));
23 export default new Proxy<PassUI>({} as any, {
25 /* In case the object gets serialized during error reporting */
26 if (property === 'toJSON') return () => ({ __type: 'PassUIProxy' });
27 if (property === Symbol.toStringTag) return 'PassUIProxy';
29 return (...args: any[]) => {
31 if (!service) throw new Error('Module not initialized');
32 return (service[property as keyof PassUI] as any)(...args);
34 if (isNativeJSError(err)) logger.warn(`[PassCoreUI] Failed executing ${property.toString()}`, err);