{"id":21708519,"url":"https://github.com/ufologist/bootup-sandbox","last_synced_at":"2025-04-12T16:30:25.698Z","repository":{"id":136686650,"uuid":"177257615","full_name":"ufologist/bootup-sandbox","owner":"ufologist","description":"在当前页面中启动一个沙箱环境, 让所有代码跑在沙箱中","archived":false,"fork":false,"pushed_at":"2023-01-03T18:22:35.000Z","size":189,"stargazers_count":8,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T10:52:19.863Z","etag":null,"topics":["iframe","inject","sandbox"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/ufologist.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":"2019-03-23T07:20:26.000Z","updated_at":"2023-11-19T09:22:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"d5380e28-073b-4f40-8bce-4c4e691be16b","html_url":"https://github.com/ufologist/bootup-sandbox","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufologist%2Fbootup-sandbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufologist%2Fbootup-sandbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufologist%2Fbootup-sandbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufologist%2Fbootup-sandbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ufologist","download_url":"https://codeload.github.com/ufologist/bootup-sandbox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248596410,"owners_count":21130698,"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":["iframe","inject","sandbox"],"created_at":"2024-11-25T22:27:34.024Z","updated_at":"2025-04-12T16:30:25.686Z","avatar_url":"https://github.com/ufologist.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bootup-sandbox\n\n[![NPM version][npm-image]][npm-url] [![Build Status][ci-status-image]][ci-status-url] [![Coverage Status][coverage-status-image]][coverage-status-url] [![Known Vulnerabilities][vulnerabilities-status-image]][vulnerabilities-status-url] [![changelog][changelog-image]][changelog-url] [![license][license-image]][license-url]\n\n[vulnerabilities-status-image]: https://snyk.io/test/npm/bootup-sandbox/badge.svg\n[vulnerabilities-status-url]: https://snyk.io/test/npm/bootup-sandbox\n[ci-status-image]: https://travis-ci.org/ufologist/bootup-sandbox.svg?branch=master\n[ci-status-url]: https://travis-ci.org/ufologist/bootup-sandbox\n[coverage-status-image]: https://coveralls.io/repos/github/ufologist/bootup-sandbox/badge.svg?branch=master\n[coverage-status-url]: https://coveralls.io/github/ufologist/bootup-sandbox\n[npm-image]: https://img.shields.io/npm/v/bootup-sandbox.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/bootup-sandbox\n[license-image]: https://img.shields.io/github/license/ufologist/bootup-sandbox.svg\n[license-url]: https://github.com/ufologist/bootup-sandbox/blob/master/LICENSE\n[changelog-image]: https://img.shields.io/badge/CHANGE-LOG-blue.svg?style=flat-square\n[changelog-url]: https://github.com/ufologist/bootup-sandbox/blob/master/CHANGELOG.md\n\n[![npm-image](https://nodei.co/npm/bootup-sandbox.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://npmjs.com/package/bootup-sandbox)\n\n在当前页面中启动一个沙箱环境, 让所有代码跑在沙箱中\n\n## 原理\n\n初衷: 在 PC 端页面中接入第三方的 IM 组件, 为了避免接入时可能存在的冲突\n\n* 在当前页面中插入一个空的 `\u003ciframe\u003e` 元素\n  * 作为独立的运行环境, 与当前页面隔离开(特别适合作为第三方的集成方案)\n  * 避免与当前页面的 `CSS`/`JS` 冲突\n* 将 `JS` 注入到 `\u003ciframe\u003e` 元素中执行\n  * 动态创建 `\u003cscript\u003e` 元素插入到 `\u003ciframe\u003e` 中\n\n灵感来源[反击爬虫，前端工程师的脑洞可以有多大？](https://imweb.io/topic/595b7161d6ca6b4f0ac71f05), 感谢网易云音乐的 FE 们\n\n\u003e iframe异步加载式\n\u003e\n\u003e 例子：[网易云音乐](https://music.163.com/)\n\u003e \n\u003e 网易云音乐页面一打开，html源码里几乎只有一个iframe，并且它的src是空白的：`about:blank`。接着js开始运行，把整个页面的框架异步塞到了iframe里面…\n\n![music 163 com](https://user-images.githubusercontent.com/167221/54866079-b819fa00-4daa-11e9-803c-c5a22d170d03.png)\n\n## Example\n\n```javascript\nimport BootupSandbox from 'bootup-sandbox';\n\nvar sandbox = new BootupSandbox();\nsandbox.injectScript('window.foo = \"bar\"', function() {\n    console.log(sandbox.window.foo);\n});\n```\n\n## APIDoc\n\n* [ESDoc](https://doc.esdoc.org/github.com/ufologist/bootup-sandbox/)\n* 兼容 IE9+\n  * `Object.defineProperty`\n  * `script.onload`\n  * `postMessage`\n  * `addEventListener`\n\n## 其他思路\n\n* [iframe-script](https://github.com/alexgorbatchev/iframe-script)\n* [create-iframe](https://github.com/sethvincent/create-iframe)\n* [iframe-sandbox](https://github.com/kumavis/iframe-sandbox)\n* [jsonp-sandbox](https://github.com/aui/jsonp-sandbox)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fufologist%2Fbootup-sandbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fufologist%2Fbootup-sandbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fufologist%2Fbootup-sandbox/lists"}