2017-09-28 59 views
-1

我构建了一个Chrome扩展程序,并且我希望它在我观看某些特定网站(如“Youtube”)时自动工作,我该如何做到这一点?任何帮助,将不胜感激。在加载特定网站时自动运行我的Chrome扩展程序

{ 
    "manifest_version": 2, 

    "name": "My extension", 
    "description": "bla bla", 
    "version": "1.0", 
    "browser_action": { 
    "default_icon": "gjx.png", 
    "default_popup": "popup.html" 
    }, 
    "permissions": [ 
    "http://localhost/*", 
    "tabs", 
    "cookies", 
    "storage" 
    ], 
    "background":["crawler.js"], 
    "content_scripts":[{ 
    "matches": ["*://*.youtube.com/*"], 
    "js": ["crawler.js"] 
    }] 
} 

回答

0

例如,这里的script.js会自动在您所在的Youtube页面上执行。

manifest.json

{ 
    "content_scripts": [{ 
     "matches": ["https://www.youtube.com/*"], 
     "js": ["script.js"] 
    }], 
    "permissions": [ 
     "tabs", "http://*/*" 
    ] 
} 

我推荐阅读比赛和内容脚本herehere

+0

我都试过了,但它不工作。 @PredatorIWD –

+0

@SiruiLi您可以将“manifest.json”和您的内容脚本添加到问题中吗? – PredatorIWD

+0

它在这里。 @PredatorIWD –

0

您需要将所需的网址格式添加到manifest.json中的permissions。 您有:

"permissions": [ 
    "http://localhost/*", 
    "tabs", 
    "cookies", 
    "storage" 
    ] 

您必须添加所需的URL模式,如:

"permissions": [ 
    "http://localhost/*", 
    "tabs", 
    "cookies", 
    "storage", 
    "*://*.youtube.com/* 
    ] 
相关问题