在谷歌浏览器插件中,注入JS代码到页面里

第一种:

const script = document.createElement("script");
script.textContent = `代码`
document.documentElement.appendChild(script);
script.remove(); 

第二种:

    const inlineScript = `
        (function() {
          代码
        })();
      `;

      const scriptTag = document.createElement('script');
      scriptTag.textContent = inlineScript;
      document.head.appendChild(scriptTag);
      scriptTag.remove();

好用的插件开发框架:wxt.dev


在谷歌浏览器插件中,注入JS代码到页面里
https://blog.jiang.in/archives/54733ab9-96c1-4564-8df3-20818cae5d74
作者
Jiang
发布于
2025年02月14日
更新于
2025年02月23日
许可协议