Readme

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.

1
2
3
4
5
console.log("This runs on import");
export function test() {
console.log("This runs when test() is called");
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
v9
May 13, 2024