Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复通过appendChild添加的外部脚本中使用document.body.removeChild移除脚本报错阻塞代码执行的问题 #839

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wyh369352887
Copy link

  • 提交符合commit规范
  • 文档更改
  • 测试用例添加
  • npm run test通过
详细描述
  • 特性
    一些第三方库内部会使用
const script = document.createElement("script");

script.onload = function () {
  document.body.removeChild(script);
};

document.body.appendChild(script)

这种形式关联自己的脚本资源,但由于wujie劫持了子应用的Node.prototype.appendChild并改变了脚本的实际执行环境,所以在removeChild的时候会报错阻塞脚本执行。

所以添加了对子应用removeChild的劫持,在调用时判断目标Node是否还与Document连接,并尝试使用Node.parentNode.removeChild进行移除。

@yiludege
Copy link
Collaborator

感谢贡献!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants