Skip to content

Instantly share code, notes, and snippets.

@humphd
Created July 24, 2023 15:36
Show Gist options
  • Save humphd/2168e398b6ba83d3fe579f63f429ef13 to your computer and use it in GitHub Desktop.
Save humphd/2168e398b6ba83d3fe579f63f429ef13 to your computer and use it in GitHub Desktop.

Revisions

  1. humphd created this gist Jul 24, 2023.
    24 changes: 24 additions & 0 deletions runJS.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    export const name = "runJS";

    export const description = "Runs arbitrary JavaScript code in a browser context (no node.js)";

    export const parameters = {
    type: "object",
    properties: {
    "code": {
    type: "string",
    description: "JavaScript code to run in browser",
    }
    }
    };

    export default async function (data) {
    const { code } = data;
    let result;
    try {
    result = eval(code);
    } catch (error) {
    result = error.toString();
    }
    return result.toString();
    }