{"id":15664712,"url":"https://github.com/perry-mitchell/slyfox","last_synced_at":"2026-04-09T00:02:29.871Z","repository":{"id":58234195,"uuid":"48590954","full_name":"perry-mitchell/slyfox","owner":"perry-mitchell","description":"Restore overwritten methods on the window.","archived":false,"fork":false,"pushed_at":"2023-12-07T11:10:37.000Z","size":268,"stargazers_count":19,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-04-01T02:44:55.559Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/perry-mitchell.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2015-12-25T20:45:54.000Z","updated_at":"2025-10-06T12:34:02.000Z","dependencies_parsed_at":"2023-12-02T19:25:26.889Z","dependency_job_id":"fa2ccb9e-d397-4d3a-a4dc-c2bb8b896b3b","html_url":"https://github.com/perry-mitchell/slyfox","commit_stats":null,"previous_names":["perry-mitchell/restore-func","perry-mitchell/archetype"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/perry-mitchell/slyfox","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perry-mitchell%2Fslyfox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perry-mitchell%2Fslyfox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perry-mitchell%2Fslyfox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perry-mitchell%2Fslyfox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/perry-mitchell","download_url":"https://codeload.github.com/perry-mitchell/slyfox/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perry-mitchell%2Fslyfox/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31579058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-03T13:43:57.284Z","updated_at":"2026-04-09T00:02:29.838Z","avatar_url":"https://github.com/perry-mitchell.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SlyFox\n\u003e Restore overwritten methods on the window and document... **Like a fox**.\n\n[![slyfox](https://img.shields.io/npm/v/slyfox?color=blue\u0026label=slyfox\u0026logo=npm\u0026style=flat-square)](https://www.npmjs.com/package/slyfox) ![Tests status](https://github.com/perry-mitchell/slyfox/actions/workflows/test.yml/badge.svg) ![GitHub](https://img.shields.io/github/license/perry-mitchell/slyfox)\n\n## About\n\nIt's entirely possible, during the execution of a web page, for JavaScript to override many of the core functions providing access to the DOM. This is generally a terrible idea - core functions like `document.createElement` have very broad use, and overriding them can be dangerous. Why would someone override such a method? There's a number of reasons apparently:\n\n * **PrototypeJS** (some versions) thought it was necessary to provide improved support\n * Companies like **Osano** believe it's their right when protecting their clients from scripts that don't properly check for data transmission consent\n * Some website owners believe that every element passing through such a method should be manipulated or scanned\n\nWhatever the reason it's simply a **bad idea**.\n\n**SlyFox** (formerly `archetype`) is a restoration library aimed at retrieving non-tampered-with method originals through the use of a \"safe\" iframe it embeds. Copies of these unaltered functions are pulled from the iframe and provided to the caller.\n\nUnlike this library's predecessor, SlyFox does _not_ write these functions over the altered versions. There's ultimately no point fighting like that. This is more of a ponyfill approach rather than a polyfill.\n\n## Installation\n\nInstall using `npm install slyfox --save-dev`.\n\nSlyFox provides both an ESM (primary) entry and a UMD build that can be directly injected into browsers. The UMD script is located at `dist/umd/index.js`. Both builds provide types.\n\n## Usage\n\nWhen using the default (ESM) entry, import the `createSession` helper to create a new `RestoreSession` instance. From there you can immediately fetch restored native methods:\n\n```typescript\nimport { createSession } from \"slyfox\";\n\nasync function program() {\n    const session = await createSession();\n    const createEl = session.getNativeMethod(\"document.createElement\");\n    const div = createEl(\"div\");\n}\n```\n\n`getNativeMethod`'s only argument is the global path to the method you want to process.\n\nWhile `getNativeMethod` provides easy access to top-level methods, it doesn't suit prototype-based methods that appear on elements as they're created. For that, you can use `getNativePrototypeMethod` (though note that it does _not_ support caching like `getNativeMethod`):\n\n```typescript\nimport { createSession } from \"slyfox\";\n\nasync function program() {\n    const session = await createSession();\n    const createEl = session.getNativeMethod(\"document.createElement\");\n    const child = createEl(\"div\");\n    const targetElement = document.getElementById(\"root\");\n    const targetAppend = session.getNativePrototypeMethod(\n        targetElement,\n        \"appendChild\",\n        \"window.Element.prototype.appendChild\"\n    );\n    targetAppend(child);\n}\n```\n\n`getNativePrototypeMethod` takes 3 arguments:\n\n 1. The element or instance to process as the context\n 2. The name of the instance's method to process\n 3. The path to the global prototype\n\nKeep the `RestoreSession` instance around and call it when needed. It caches fetched/bound methods so it doesn't have to reproduce them again every call.\n\nYou can also pre-cache some function lookups so you might potentially capture the un-modified versions if you're early enough:\n\n```typescript\nsession.precacheMethods([\n    \"document.createElement\",\n    \"document.body.appendChild\"\n]);\n```\n\n### Caveats\n\nRemember that the returned functions from `getNativeMethod` are _not_ identical to the original function that was overwritten. That original is either lost or not provided via this library. What is returned is either:\n\n * The original function, but bound to its parent. Eg. `document.querySelector.bind(document)`.\n * A recovered copy from another _iframe_, bound to the parent of the top/target frame.\n\nIn any case, the elements you interact with, potentially, might not function in the way you'd expect them too with normal calls. Never use `instanceof` as this might return unexpected values when using this library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperry-mitchell%2Fslyfox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperry-mitchell%2Fslyfox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperry-mitchell%2Fslyfox/lists"}