Task tutorial

Add a browser molecule check with a pinned CDN module

Load the published WebAssembly package in a small browser page without adding a bundler or a backend.

You will make

A browser console result for aspirin using a release-pinned module import.

Steps

  1. Create a small HTML page served from HTTPS or a local web server.
  2. Paste the pinned module script below and load the page in a browser.
  3. Confirm that the console prints 180.16 for aspirin, then release the molecule object.
<script type="module">
  import init, { parse_smiles } from "https://cdn.jsdelivr.net/npm/@kent-tokyo/chematic@1.1.7/chematic_wasm.js";

  await init();
  const mol = parse_smiles("CC(=O)Oc1ccccc1C(=O)O"); // aspirin
  console.log(mol.molecular_weight().toFixed(2)); // 180.16
  mol.free();
</script>

Expected result

After the pinned WebAssembly module initializes, the browser console prints 180.16 for the aspirin molecular weight. The SMILES calculation runs in the browser.

If it does not work

Do not replace the explicit release version with @latest. A file URL can block ES modules in some browsers, so use a local server; package delivery from a CDN is separate from sending molecule input to chematic.io.

Next action

Read the browser and WebAssembly guide