1 import browser from '@proton/pass/lib/globals/browser';
2 import type { MaybeNull } from '@proton/pass/types';
3 import { logger } from '@proton/pass/utils/logger';
5 import type { PassCore, PassCoreService } from './types';
7 export const createPassCoreSyncService = (): PassCoreService => {
8 let wasmPromise: MaybeNull<Promise<PassCore>> = null;
10 const loadWASM = async () =>
11 (wasmPromise = wasmPromise ?? import(/* webpackChunkName: "pass-core" */ '@protontech/pass-rust-core')).catch(
13 /** Chrome extensions may encounter internal runtime errors (ie: `ChromeMethodBFE`)
14 * during WASM instantiation. We explicitly read `browser.runtime.lastError` to
15 * prevent these errors from interfering with other extension API calls. */
16 void browser.runtime?.lastError;
21 const service: PassCoreService = {
22 exec: async (method, ...args) => {
24 const core = await loadWASM();
25 return (core[method] as any)(...args);
27 logger.warn(`[PassCore] Failed executing ${method}`, err);
28 throw new Error('PassCore not initialized');