我想念没有显示弹出窗口吗?
在弹出文件夹中,我有四个文件。我将该文件作为扩展名加载。我可以看到该图标,但是当我单击它时,弹出窗口没有显示出来。为什么?
{
"name": "Popup poc",
"version": "1.4",
"description": "Simple popup example",
"content_scripts": [
{
"matches": [""],
"js": ["content_script.js"]
}
],
"page_action": {
"default_name": "Display Map",
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"manifest_version": 2
}
<!doctype html>
<html>
<head>
<title>Popup</title>
</head>
<body>
This is body
</body>
</html>
答案 0 :(得分:4)
在page_action
中用“ browser_action
”替换“ manifest.json
”。这样,您应该可以在所有页面上看到弹出窗口。
可能与以下内容重复:Chrome extension popup not showing anymore 但似乎我没有足够的声誉分数对其进行标记。
编辑: 如果您想在Google上显示弹出式窗口,则需要在清单中指定“ declarativeContent”权限,该权限也是背景脚本。 这样您的清单将如下所示:
{
"name": "Popup poc",
"version": "1.4",
"description": "Simple popup example",
"permissions": ["declarativeContent"],
"content_scripts": [
{
"matches": ["https://www.google.com/*"],
"js": ["content_script.js"]
}
],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"page_action": {
"default_name": "Display Map",
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"manifest_version": 2
}
您的background.js如下:
chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([{
conditions: [new chrome.declarativeContent.PageStateMatcher({
pageUrl: {hostEquals: 'www.google.com'},
})
],
actions: [new chrome.declarativeContent.ShowPageAction()]
}]);
});
});
此代码主要来自Getting Started Tutorial