在谷歌浏览器插件中,注入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