Chrome extension with imports

To write a Chrome extension that allows ES6 imports, imitate <script type="module"> with a dynamic import:

// content_script.js

// Imitate: <script type="module" src="page_script.js"></script>
(async () => {
  const src = chrome.extension.getURL('page_script.js');
  const pageScript = await import(src);
  pageScript.init()
})();
// page_script.js

import { bird, owl, goose } from './bird_scripts.js';

export function init() {
  // Do bird stuff.
  bird();
}

Links

Leave a Reply

Your email address will not be published. Required fields are marked *