I have been learning to create a chrome extension. I have tried hello world example and it was working fine. Now I have been trying to add custom code and make some changes
There is no right-side panel in chrome extension API.
By you may do it in the same way, as your example extension does:
background.js
listening messages from the tabbackground.js
if the tab is injectable (if you need your extension work correct on system pages)chrome.tabs.executeScript
inject your menu div to the page / inject listener, which opens your menu.background.js
listening browser icon clicks and notify your content script about clicks.popup.html
in default popup.manifest.js
....
"browser_action": {
},
"background": {
"scripts":["background.js"]
},
...
background.js
chrome.browserAction.onClicked.addListener(function(tab){
chrome.tabs.sendMessage(tab.id,"toggle");
});
zero width
on with display:none;
style). I use zero width
because of you may want to animate your menu display by jquery as example extension does.background.js
script.content-script.js
chrome.runtime.onMessage.addListener(function(msg, sender){
if(msg == "toggle"){
toggle();
}
})
var iframe = document.createElement('iframe');
iframe.style.background = "green";
iframe.style.height = "100%";
iframe.style.width = "0px";
iframe.style.position = "fixed";
iframe.style.top = "0px";
iframe.style.right = "0px";
iframe.style.zIndex = "9000000000000000000";
iframe.frameBorder = "none";
iframe.src = chrome.extension.getURL("popup.html")
document.body.appendChild(iframe);
function toggle(){
if(iframe.style.width == "0px"){
iframe.style.width="400px";
}
else{
iframe.style.width="0px";
}
}
manifest.json
"web_accessible_resources": ["popup.html"]