Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to edit a chrome extension manifest file from within the extension?

I want to allow the user to select the icon that appears for their extension from a list. Is there a way to edit the manifest from within the extension?

So If I have the following in my chrome extension manifest file:

  "browser_action": {
    "default_icon": "ico32.gif",
  }

And I want to give the user the ability to change it to the following from within the extension itself:

  "browser_action": {
    "default_icon": "ico32green.gif",
  }

Is there a way to do that?

like image 682
cmcculloh Avatar asked Dec 10 '09 18:12

cmcculloh


People also ask

Can you modify Chrome extensions?

Chrome allows you to add as many extensions as you want. That being said, sometimes it can be difficult to find the page where you can change Chrome extension settings. From the Chrome extension settings page, you can perform functions like removing current, deactivating or activating your current extensions.

How do I modify an extension?

You can also do it by right-clicking on the unopened file and clicking on the “Rename” option. Simply change the extension to whatever file format you want and your computer will do the conversion work for you.

How do I edit a CRX file?

. CRX files are like . ZIP files, just change the extension and right click > Extract Files and you are done. Once you have extracted files --> modify them and add to zip and change extension back to .

Can you unpack a Chrome extension?

Goto Chrome Settings using three dots on the top right corner. Then Select Extensions. Click on Load Unpacked and select your Unzip folder. Note: You need to select the folder in which the manifest file exists.


1 Answers

There is no way to directly edit the manifest file. However, you can use the following work around to modify the property on browser load. This particular code sets the icon on browser load and allows the user to specify what icon should be set on browser load:

In manifest.json:

{
  "browser_action": {
    "default_icon": "ico32.gif",
  },
  "options_page": "options.html",
  "background_page":"background.html"
}

In background_page:

<script>
var icon = localStorage["icon"];
if(icon == undefined){
    icon = "ico32.gif";
    localStorage["icon"] = icon;
}

chrome.browserAction.setIcon({"path":localStorage["icon"]});
</script>

In options page:

<html>
<body>
<h1>Choose you color:</h1>
<p>
    <img class="color" src="ico48.gif" />
    <img class="color" src="icoGreen.gif" />
    <img class="color" src="icoPurple.gif" />
    <img class="color" src="icoRed.gif" />
</p>
<script>
var colors = document.getElementsByClassName("color");
for(var i=0,ii=colors.length;i<ii;i++){
    colors[i].addEventListener("click", changeColor);
}

function changeColor(e){
    localStorage["icon"] = e.target.src;
    chrome.browserAction.setIcon({"path":localStorage["icon"]});
}
</script>
</body>
</html>
like image 161
cmcculloh Avatar answered Sep 20 '22 13:09

cmcculloh