sla*_*yer 15 javascript jquery google-chrome google-chrome-extension
我对chrome扩展开发很新.
问题不在于访问chrome:// url我不想在那里编辑任何内容,但问题在于执行用于注入脚本的chrome.tabs.executeScript().
我正在尝试使用chrome .tabs.executeScript运行后台脚本,但它会出现以下错误:
我有以下代码:
表现
{
"name": "BrowserExtension",
"version": "0.0.1",
"manifest_version": 2,
"description" : "Description ...",
"icons": { "16": "icons/16x16.png", "48": "icons/48x48.png", "128": "icons/128x128.png" },
"background" : {
"scripts": ["background.js"]
},
"permissions": [
"tabs",
"background",
"http://*/*",
"https://*/*"
],
"browser_action": {
"default_icon": {
"19": "icons/19x19.png",
"38": "icons/38x38.png"
},
"default_title": "That's the tool tip"
}
}
Run Code Online (Sandbox Code Playgroud)
Background.js
console.log("background.js : click()");
chrome.tabs.executeScript(null, {file: "jquery.min.js"}, function(){
chrome.tabs.executeScript(null, {file: "auto.js"}, function(){
chrome.tabs.executeScript(null, {file: "script.js"}, function(){
//all injected
});
});
});
Run Code Online (Sandbox Code Playgroud)
的script.js
$(function()
{
var input = $('input');
$.each(input,function(index,element){
var area = new AutoSuggestControl(element.id);
});
var ta = $('textarea');
$.each(ta,function(index,element){ var area = new AutoSuggestControl(element.id);});
return 1;
});
Run Code Online (Sandbox Code Playgroud)
auto.js是一个预编译的js文件,在html文件中单独使用时效果很好.扩展的目的是在文本字段中写入时提供自动完成.非常感谢帮助.
Mar*_*lin 11
chrome:// url因安全原因被阻止.Google不希望您在用户不知情的情况下更改外观或更改Chrome设置.当您加载扩展程序时,它会立即在chrome:// extensions页面中执行这些文件.如果要在用户访问的每个选项卡中执行脚本,则应使用:
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
//code in here will run every time a user goes onto a new tab, so you can insert your scripts into every new tab
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24031 次 |
| 最近记录: |