{"id":14965742,"url":"https://github.com/stagas/run-in-client","last_synced_at":"2026-01-28T05:25:31.191Z","repository":{"id":57155764,"uuid":"440963956","full_name":"stagas/run-in-client","owner":"stagas","description":"runs a single function in the client using puppeteer and esbuild","archived":false,"fork":false,"pushed_at":"2022-02-04T11:35:39.000Z","size":25,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-15T04:19:06.347Z","etag":null,"topics":["esbuild","function","puppeteer","test","testing","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stagas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-22T19:30:09.000Z","updated_at":"2021-12-23T07:05:50.000Z","dependencies_parsed_at":"2022-08-26T08:31:07.538Z","dependency_job_id":null,"html_url":"https://github.com/stagas/run-in-client","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":"stagas/ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stagas%2Frun-in-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stagas%2Frun-in-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stagas%2Frun-in-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stagas%2Frun-in-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stagas","download_url":"https://codeload.github.com/stagas/run-in-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008598,"owners_count":21032554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esbuild","function","puppeteer","test","testing","typescript"],"created_at":"2024-09-24T13:35:13.663Z","updated_at":"2026-01-28T05:25:29.175Z","avatar_url":"https://github.com/stagas.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003erun-in-client\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\nruns a single function in the client using puppeteer and esbuild\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n   \u003ca href=\"#install\"\u003e        🔧 \u003cstrong\u003eInstall\u003c/strong\u003e\u003c/a\u003e\n · \u003ca href=\"#example\"\u003e        🧩 \u003cstrong\u003eExample\u003c/strong\u003e\u003c/a\u003e\n · \u003ca href=\"#api\"\u003e            📜 \u003cstrong\u003eAPI docs\u003c/strong\u003e\u003c/a\u003e\n · \u003ca href=\"https://github.com/stagas/run-in-client/releases\"\u003e 🔥 \u003cstrong\u003eReleases\u003c/strong\u003e\u003c/a\u003e\n · \u003ca href=\"#contribute\"\u003e     💪🏼 \u003cstrong\u003eContribute\u003c/strong\u003e\u003c/a\u003e\n · \u003ca href=\"https://github.com/stagas/run-in-client/issues\"\u003e   🖐️ \u003cstrong\u003eHelp\u003c/strong\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n***\n\n## Install\n\n```sh\n$ npm i run-in-client\n```\n\n## API\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n#### Table of Contents\n\n*   [runInClient](#runinclient)\n    *   [Parameters](#parameters)\n\n### runInClient\n\n[src/index.ts:43-92](https://github.com/stagas/run-in-client/blob/73a6c003203299a30c1469173e1a00bcd43a986d/src/index.ts#L43-L92 \"Source code on GitHub\")\n\nCreates a static server with esbuild transforms, creates a puppeteer instance,\nexecutes a single function, returns its result and tears down.\n\n```ts\nconst setup = {\n  root: path.resolve(path.join(__dirname, '..')),\n  include: `\n    import { someModule } from './some-module.ts' // note we can import .ts files\n    window.someModule = someModule\n  `,\n}\n\n// this is how our function below gets intellisense\ndeclare window: WindowOrWorkerGlobalScope \u0026 { someModule: typeof someModule }\n\n// the function runs in the client, as such doesn't have access to the scope!\nconst result = await runInClient(setup, async () =\u003e {\n  const output = await window.someModule.doSomething()\n  return output\n})\n// =\u003e `result` is now `output`\n```\n\n#### Parameters\n\n*   `setup` **ClientSetup** A setup object\n\n    *   `setup.root`  The static root directory to serve and esbuild transform files from\n    *   `setup.include`  JavaScript to run before the function, like import statements\n    *   `setup.buildOptions`  Esbuild build options (@see \u003chttps://esbuild.github.io/api/#build-api\u003e)\n    *   `setup.launchOptions`  Puppeteer launch options (@see \u003chttps://puppeteer.github.io/puppeteer/docs/puppeteer.launch/\u003e)\n*   `fn` **function (): any** The function to run. This will be passed in `page.evaluate(fn)`\n\nReturns **any** The result value of `page.evaluate(fn)`\n\n## Contribute\n\n[Fork](https://github.com/stagas/run-in-client/fork) or\n[edit](https://github.dev/stagas/run-in-client) and submit a PR.\n\nAll contributions are welcome!\n\n## License\n\nMIT © 2021\n[stagas](https://github.com/stagas)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstagas%2Frun-in-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstagas%2Frun-in-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstagas%2Frun-in-client/lists"}