impl.ts
 1  import type { ManifestParserInterface, Manifest } from './type';
 2  
 3  export const ManifestParserImpl: ManifestParserInterface = {
 4    convertManifestToString: (manifest, env) => {
 5      if (env === 'firefox') {
 6        manifest = convertToFirefoxCompatibleManifest(manifest);
 7      }
 8      return JSON.stringify(manifest, null, 2);
 9    },
10  };
11  
12  function convertToFirefoxCompatibleManifest(manifest: Manifest) {
13    const manifestCopy = {
14      ...manifest,
15    } as { [key: string]: unknown };
16  
17    manifestCopy.background = {
18      scripts: [manifest.background?.service_worker],
19      type: 'module',
20    };
21    manifestCopy.options_ui = {
22      page: manifest.options_page,
23      browser_style: false,
24    };
25    manifestCopy.content_security_policy = {
26      extension_pages: "script-src 'self'; object-src 'self'",
27    };
28    manifestCopy.browser_specific_settings = {
29      gecko: {
30        id: 'example@example.com',
31        strict_min_version: '109.0',
32      },
33    };
34    delete manifestCopy.options_page;
35    return manifestCopy as Manifest;
36  }