且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在网页的任何脚本运行之前,是否可以在网页上下文中使用chrome扩展来运行脚本?

更新时间:2023-10-28 15:35:04

根元素始终存在。您可以将< script> 附加到< html> 元素:

The root element always exist. You can just append the <script> to the <html> element:

var s = document.createElement('script');
s.textContent = 'console.log("Test");';
document.documentElement.appendChild(s);
s.parentNode.removeChild(s); // Just to clean-up.