Skip to content

Commit 6335ed5

Browse files
fix: failed to fetch dynamatically imported module issue (#6039)
1 parent 9b62271 commit 6335ed5

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

extension/js/common/platform/catch.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
'use strict';
44

5+
import type { ExternalService as IExternalService } from '../api/account-servers/external-service.js';
6+
import { Env } from '../browser/env.js';
57
import { Url } from '../core/common.js';
68
import { FLAVOR, VERSION } from '../core/const.js';
79
import { CatchHelper } from './catch-helper.js';
@@ -284,9 +286,26 @@ export class Catch {
284286
return;
285287
}
286288

287-
// eslint-disable-next-line @typescript-eslint/naming-convention
288-
const { ExternalService } = await import('../api/account-servers/external-service.js');
289-
const externalService = new ExternalService(acctEmail);
289+
let externalService: IExternalService;
290+
if (Env.isContentScript()) {
291+
/**
292+
* – In content-script builds, the class is already bundled in `webmail_bundle.js`
293+
* so we just grab it from the global scope.
294+
* ⚠️ If we *ever* try to dynamically import this module from a content-script
295+
* the browser will throw:
296+
* “Denying load of chrome-extension://…/external-service.js.
297+
* Resources (including all dependencies this file uses) must be listed in the web_accessible_resources manifest key”
298+
*/
299+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
300+
// @ts-expect-error
301+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
302+
externalService = new ExternalService(acctEmail);
303+
} else {
304+
// eslint-disable-next-line @typescript-eslint/naming-convention
305+
const { ExternalService } = await import('../api/account-servers/external-service.js');
306+
externalService = new ExternalService(acctEmail);
307+
}
308+
290309
await externalService.setUrlBasedOnFesStatus();
291310
await externalService.reportException(errorReport);
292311
}

0 commit comments

Comments
 (0)