3

だから私は自分のクロム拡張機能を書いていて、次の content_scripts を持っています:

"content_scripts": [{
    "matches": ["*://*.youtube.com/*"],
    "exclude_globs": ["*user*"],
    "css": ["youtube.css"]
}]

ご覧のとおり、YouTube で実行されています。ただし、youtube.com/user/ では実行しないでください。そのため、exclude_globs フィールドがあります。ただし、機能せず、ユーザーのチャンネルを表示しているときに実行されます。誰でもアイデアはありますか?

4

1 に答える 1

2

回避策としてinsertCSSを使用するため、これはChromeの既知のバグです。

元:

次のコードbackground.jsは、と同じ仕事をしますmanifest.json

//Use chrome.tabs.onUpdated.addListener(function(integer tabId, object changeInfo, Tab tab) {...}); as applicable to ensure it works on every page     
chrome.browserAction.onClicked.addListener(function (tab) {
        chrome.tabs.insertCSS(null, {
            code: "document.body.bgColor='red'",
            "all_frames": true
        });
    });

また

//Use chrome.tabs.onUpdated.addListener(function(integer tabId, object changeInfo, Tab tab) {...}); as applicable to ensure it works on every page
 chrome.browserAction.onClicked.addListener(function (tab) {
    chrome.tabs.insertCSS(null, {
        file: {file:"content.css"},
        "all_frames": true
    });
});

マニフェストに十分な権限があることを確認してください

/* in manifest.json */
"permissions": [
  "tabs", "http://*/*"
],

参考文献

a) CSSを挿入

b)プログラムによるインジェクション

お役に立てれば。

于 2012-12-09T23:34:28.333 に答える