[英]How to ensure a chrome extension does not just work on local HTML files
我一直致力于Chrome扩展,其目的是从类似于https://secure.state.gov/的域中提取某些页面的公共数据。 为了开发,我已经在本地保存了一些HTML文件,并且已经对它们进行了测试。 现在我已经开始工作了,我想尝试使用一些实时公共页面进行扩展。 但是,当我点击该域中的扩展程序时,所有显示的内容都是默认的Google扩展程序菜单,而不是我创建的工作本地页面的popup.html。 除了本地HTML页面之外的任何网页上的此行为都是相同的。
在清单文件中,我尝试在权限和content_scripts中添加“”。
"name": "APPNAME!",
"version": "1.0",
"description": "DESCRIPTION REDACTED!",
"permissions": ["activeTab", "declarativeContent", "storage" , "*://secure.state.gov/*", "<all_urls>"],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"options_page": "formMenu.html",
"page_action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
}
},
"icons": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
},
"manifest_version": 2,
"content_security_policy": "script-src 'self' https://code.jquery.com https://cdnjs.cloudflare.com https://stackpath.bootstrapcdn.com https://use.fontawesome.com; object-src 'self'",
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["payload.js"],
"run_at": "document_end"
} ]
}
没有错误消息。 我只是获取默认扩展菜单(“此网站可以读取和更改网站数据>”,“选项”,“从Chrome中删除”,“在Chrome菜单中隐藏”,“管理扩展程序”,检查弹出窗口)
要设置Chrome扩展程序以便使用本地HTML文件和特定域进行测试,请将其设置为background.js文件,如下所示:
'use strict'; chrome.runtime.onInstalled.addListener(function() { chrome.declarativeContent.onPageChanged.removeRules(undefined, function() { chrome.declarativeContent.onPageChanged.addRules([{ conditions: [ new chrome.declarativeContent.PageStateMatcher({ pageUrl: { hostEquals: '' }, }), new chrome.declarativeContent.PageStateMatcher({ pageUrl: { hostContains: 'secure.state.gov' }, }) ], actions: [new chrome.declarativeContent.ShowPageAction()] }]); }); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.