问题描述
我正在尝试将 CSS 代码从 chrome 扩展程序注入到活动选项卡中,但到目前为止,我在网上看过的任何内容都没有对我有用。我对这一切都很陌生,所以如果我的问题有点幼稚而我只是错过了一些基本的东西,我深表歉意。到目前为止,这是我想出的:
function inject_1(){
chrome.tabs.query({active: true,currentWindow: true},function(tabs) {
css = 'body { background-color = "red" !important; }';
chrome.scripting.insertCSS(
{
target: {tabId: tabs[0].id},css: css,},function() {
if (chrome.runtime.lastError) {
message.innerText = 'There was an error injecting css : \n' + chrome.runtime.lastError.message;
}
});
});
}
这是我尝试的辅助方法:
function inject_2(){
chrome.tabs.query({active: true,function(tabs) {
chrome.scripting.executeScript(
{
target: {tabId: tabs[0].id},files: ["inject.css"],function() {
if (chrome.runtime.lastError) {
message.innerText = 'There was an error injecting css : \n' + chrome.runtime.lastError.message;
}
});
});
}
这两个函数都不会返回错误消息,但它们也根本不会更改网页。我将不胜感激这方面的任何帮助(重新编写我的代码或尝试一些全新的东西)。谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)