{"id":17993391,"url":"https://github.com/vendicated/jsposed","last_synced_at":"2025-07-30T07:04:20.728Z","repository":{"id":103180950,"uuid":"479461959","full_name":"Vendicated/JsPosed","owner":"Vendicated","description":"A javascript function patcher / monkeypatcher inspired by Xposed","archived":false,"fork":false,"pushed_at":"2023-05-26T20:30:54.000Z","size":35,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-06T17:52:32.965Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/jsposed","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"osl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Vendicated.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"Vendicated"}},"created_at":"2022-04-08T16:24:32.000Z","updated_at":"2025-01-09T09:14:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"02c19bb1-617b-471a-89ea-5b7fe5f2a025","html_url":"https://github.com/Vendicated/JsPosed","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Vendicated/JsPosed","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vendicated%2FJsPosed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vendicated%2FJsPosed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vendicated%2FJsPosed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vendicated%2FJsPosed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vendicated","download_url":"https://codeload.github.com/Vendicated/JsPosed/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vendicated%2FJsPosed/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267827337,"owners_count":24150345,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-29T20:11:15.759Z","updated_at":"2025-07-30T07:04:20.707Z","avatar_url":"https://github.com/Vendicated.png","language":"TypeScript","funding_links":["https://github.com/sponsors/Vendicated"],"categories":[],"sub_categories":[],"readme":"# jsposed\n\nA javascript patching library inspired by Xposed\n\n### Installing\n\n```sh\nnpm install jsposed\n\npnpm add jsposed\n\nyarn add jsposed\n```\n\n### Usage\n\n#### Basics\nImport the Patcher class from jsposed:\n```js\nimport { Patcher } from \"jsposed\";\n```\n\nCreate a new instance. The name is used for logging errors and optional (defaults to \"JsPosed\")\n```js\nconst patcher = new Patcher(\"MyPatcherName\");\n```\n\nThe patcher will catch all errors thrown by patch callbacks and by default print them with a lot of info.\nIf you want to use your own logger or do more with the errors, you may pass your own error callback:\n```js\nconst patcher = new Patcher(\"MyPatcher\", (kind, info, error, patch) =\u003e {\n    console.error(\"Oh no :( Very bad thing happened while patching\", info.methodName);\n})\n```\n\n#### Patch types\nThere are three types of patches:\n- before: Runs **before** the original method and optionally may skip calling the original method by setting context.result (more info below)\n- instead: Runs **instead of** the original method. This will entirely skip the original method and requires you to return your own result if applicable\n- after: Runs **after** the original method and thus has access to the result returned by it\n\nYou can either use the shortcut methods `patcher.before`, `patcher.instead` and `patcher.after`...:\n```js\npatcher.before(window, \"open\", (context) =\u003e {\n    console.log(\"before window.open\", context.args[0]);\n    context.args[0] = \"https://www.youtube.com/watch?v=dQw4w9WgXcQ\";\n});\n\npatcher.after(window, \"open\", (context) =\u003e {\n    console.log(\"after window.open\", context.result)\n})\n```\n\n...or if you want to use both before and after more concisely, you may also create your own patch directly:\n```js\npatcher.patch(window, \"open\", new Patch({\n    before(context) { },\n    after(context) { }\n}))\n```\n\n#### The Patch callback\n\nWhat all patches have in common is how their callback works:\n- The first argument is a context that contains a lot of info about the invoked function and allows you to alter the arguments and result (see table below)\n- For convenience and a nicer typescript experience, the arguments passed to the original function are also available as arg 2, 3, ..., n\n\n##### PatchContext\n\n| Field | Description | in before patches | in after patches |\n|-------|-------------|--------|-------|\n| thisObject | The `this` value of this function call | - | - |\n| args | The arguments passed in this function call | Changing this array will change the arguments passed to the original | - |\n| result | The result (return value) of this function call | Always unset. Setting it to anything (including undefined) will skip the original function | Always set. Changing it will change what's eventually returned |\n| error | The error thrown by the original function | Always unset. Setting it to a non-nullish value will skip the original function and **throw** that value | Might be set if the original function threw an error. Setting it to a non-nullish value will **throw** that value. Resetting it to a nullish value will prevent errors from being thrown |\n| resultOrError | Throws context.error if non-nullish, otherwise returns context.result | Always unset | Always set\n\n### Examples\n\nFor more examples on real functions, check [tests/index.js](tests/index.js)\n\n```js\nconst { Patcher } = require(\"jsposed\");\n\nconst patcher = new Patcher();\n\n// Replace an argument before a method is called\nconst unpatch = patcher.before(someObject, \"someMethod\", (context, arg1) =\u003e {\n    context.args[0] = \"Replace some arg\";\n});\n\n// Remove that patch again\nunpatch.unpatch();\n\n// Skip a method conditionally\npatcher.before(someObject, \"slap\", (context, person) =\u003e {\n    if (person.name === \"Tom\") {\n        // Hey now, who in their right mind would slap poor Tom\n\n        // Lets skip this method\n        context.result = null; // Or some other value, this will be returned to the caller\n\n        // Or maybe you would want to throw an error?\n        context.error = new Error(\"DO NOT THE TOM!!\");\n    }\n});\n\n// Replace a method entirely\npatcher.instead(someObject, \"someMethod\", (context) =\u003e {\n    context.thisObject.doSomeOtherThing();\n})\n\n// Call the original method\n// If you really really want to slap Tom, then I guess go ahead...\npatcher.callOriginal(someObject.slap, someObject, \"Tom\");\n\n// Now remove all patches again\npatcher.unpatchAll();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvendicated%2Fjsposed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvendicated%2Fjsposed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvendicated%2Fjsposed/lists"}