使用page_action时,Popup不显示 [英] Popup is not appearing when used page_action
问题描述
我是Google Chrome扩展程序开发的新手。我有以下两个查询
-
当我使用
page_action $ c时,弹出窗口不显示$ c>在manifest.json中,但在使用
browser_action
时出现。我想知道为什么?或者我做错了 -
此图标显示非活动状态。当我使用
browser_action
时,图标显示处于活动状态(意味着如果处于活动状态,我可以看到该颜色,或者在无效时我可以看到黑白图标)
Manifest.json
{
manifest_version:2,
name:入门示例,
description:该扩展插件显示Google图片搜索结果对于当前页面,
version:1.0,
page_action:{
default_icon:icon.png,
default_popup:popup.html,
default_title:getStarted Extension
},
permissions:[
activeTab,
https ://ajax.googleapis.com/
}
更新:
感谢 Teepemm 。按照他的解释,并用代码添加了答案。
感谢 Teepemm 用于指导我的正确解释,因此为了使图标处于活动状态,您必须使用 chrome.pageAction.show(tabId)
(激活图标)和 chrome.pageAction.hide(tabId)
(取消激活图标)=> https://developer.chrome.com/extensions/pageAction#method-show
您需要通过从client.js中调用此方法来调用此方法
// background .js
chrome.extension.onMessage.addListener(
函数(request,sender,sendResponse){
if(request.message ===activate_icon){
chrome。 pageAction.show(sender.tab.id);
}
});
//content-script.js
chrome.runtime.sendMessage({message:activate_icon});
因此,一旦您的分机图标处于活动状态,只需点击图标,弹出窗口就会出现。所以弹出窗口只会在图标处于活动状态时才会出现。
希望这有助于
I am new to Google Chrome extension development. I am having the two following queries
Popup is not appearing when I use
page_action
in manifest.json but appearing when I usedbrowser_action
. I would like to know why? Or am I doing wrongAlso the icon is showing inactive state. Where as when I use
browser_action
, the icon is showing in active state (means I could see the color if active, or I could see as black and white icon, when inactive)
Manifest.json
{
"manifest_version": 2,
"name": "Getting started example",
"description": "This extension shows a Google Image search result for the current page",
"version": "1.0",
"page_action": {
"default_icon": "icon.png",
"default_popup": "popup.html",
"default_title":"getStarted Extension"
},
"permissions": [
"activeTab",
"https://ajax.googleapis.com/"
]
}
UPDATE:
Thanks to Teepemm . Followed his explanation and added the answer with code
Thanks to Teepemm for guiding me with proper explanation, so in order to make the icon active and inactive, you have to use chrome.pageAction.show(tabId)
(to activate the icon) and chrome.pageAction.hide(tabId)
(to deactivate the icon) => https://developer.chrome.com/extensions/pageAction#method-show
You need to call this method from background.js by invoking it from client.js
//background.js
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.message === "activate_icon") {
chrome.pageAction.show(sender.tab.id);
}
});
//content-script.js
chrome.runtime.sendMessage({"message": "activate_icon"});
So once your extension icon is active, on click of the icon, popup will appear. So the popup will appear only when icon is active.
Hope this helps
这篇关于使用page_action时,Popup不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!