impl.ts 993 B

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