Import a val script in the chrome console

Say you're developing a chrome extension or some other little script and you're iterating in the chrome console. Over time you may write larger pieces of code that you want to save as a group. Or maybe you want to use TypeScript, which isn't supported in browsers natively. Val Town can provide a decent workflow here.

  1. Save your code in a Script val
  2. Ensure the val is Public or Unlisted
  3. In the chrome console, import your val's module url. For example, for this val it would look like this:
let {test} = await import(`https://esm.town/v/stevekrouse/importValInChromeConsole?${Math.random()}`)

I added a random number to the end of the string to prevent your browser from caching the import. So now you can save in Val Town and then re-run your import line in the Chrome console and the script will re-run in the Chrome console.

Migrated from folder: Archive/importValInChromeConsole