How do I directly modify a Google Chrome Extension File? (.CRX) - google-chrome

I'm not sure in which languages those extensions are, I think the are written in Html, Javascript or JSON. As far as I know they are "compressed" in a .CRX file.
It is possible to directly modify the html, js, json of a Chrome Extension (or whatever language they use)?

Installed Chrome extension directories are listed below:
Copy the folder of the extension you wish to modify. ( Named according to the extension ID, to find the ID of the extension, go to chrome://extensions/). Once copied, you have to remove the _metadata folder.
From chrome://extensions in Developer mode select Load unpacked extension... and select your copied extension folder, if it contains a subfolder this is named by the version, select this version folder where there is a manifest file, this file is necessary for Chrome.
Make your changes, then select reload and refresh the page for your extension to see your changes.
Chrome extension directories
Mac:
/Users/username/Library/Application Support/Google/Chrome/Default/Extensions
Windows 7:
C:\Users\username\AppData\Local\Google\Chrome\User Data\Default\Extensions
Windows XP:
C:\Documents and Settings\YourUserName\Local Settings\Application Data\Google\Chrome\User Data\Default
Ubuntu 14.04:
~/.config/google-chrome/Default/Extensions/

I searched it in Google and I found this:
The Google Chrome Extension file type is CRX. It is essentially a compression format. So if you want to see what is behind an extension, the scripts and the code, just change the file-type from “CRX” to “ZIP” .
Unzip the file and you will get all the info you need. This way you can see the guts, learn how to write an extension yourself, or modify it for your own needs.
Then you can pack it back up with Chrome’s internal tools which automatically create the file back into CRX. Installing it just requires a click.

A signed CRX file has a header that will cause most/all unzippers to barf. This is not the easiest way to go about it, but here's how to do it from a bash command line.
The basic idea is to find where the original unsigned zipfile begins, then copy the CRX file to a zip file but exclude the CRX header.
hexdump -C the_extension.crx | more
Look in the output for the start of the zip file, which are the ASCII bytes "PK". In the sample I tried, the PK was at offset 0x132. (From reading the CRX spec, I think this number will vary from file to file because of different signature lengths.) That number is what we'll use in the next step.
dd if=the_extension.crx of=the_extension.zip bs=1 skip=0x132 (For the skip parameter, substitute the offset you found in the previous step.)
Now unzip the .zip that you just created.
Fiddle with the files in the unzipped directory, then either install the unsigned/unpacked extension into your Chrome installation, or else repackage it just as you would any other Chrome extension.
I'm sure that there is a more concise way to do this. Bash experts, please improve on my answer.

Note that some zip programs have trouble unzipping a CRX like sathish described - if this is the case, try using 7-Zip - http://www.7-zip.org/

I have read the other answers and found it important to note a few other things:
1.) For Mac users: When you click "Load unpacked extension...", the Library folder is by default hidden and (even if the Show Hidden files option is toggled on your Mac) it might not show up in Chrome's finder window.
2.) The sub folder containing the extension is a random alpha-numeric string named after the extension's ID, which can be found on Chrome's extension page if Developer flag is set to true. (Upper right hand checkbox on the extensions page)

(Already said) I found this out while making some Chrome themes (which are long gone now... :-P)
Chrome themes, extensions, etc. are just compressed files. Get 7-zip or WinRar to unzip it. Each extension/theme has a manifest.json file. Open the manifest.json file in notepad. Then, if you know the coding, modify the code. There will be some other files. If you look in the manifest file you might be able to figure out what the are for. Then, you can change everything...

.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 .crx.
Other way around --> Open Chrome --> Settings --> Extensions --> Enable Developer Options --> Load unpacked Extension (modified extracted files folder) and then click pack extension.
Source

Now Chrome is multi-user so Extensions should be nested under the OS user profile then the Chrome user profile, My first Chrome user was called Profile 1, my Extensions path was C:\Users\ username \AppData\Local\Google\Chrome\User Data\ Profile 1 \Extensions\.
To find yours Navigate to chrome://version/ (I use about: out of laziness).
Notice the Profile Path and just append \Extensions\ and you have yours.
Hope this brings this info on this question up to date more.

It's possible to modify the code of .CRX extension, because it's a simple .zip archive. You can download extension, extract it's source code, modify it (test and debug it as it's on your side), and package back into .CRX file.
I googled out this tool to simply download .CRX extension and extract the source code and it worked for me: http://crxextractor.com
Everything it does is parses .CRX file format and extracts actual .zip containing the source code.

If you have installed the Portable version of Chrome, or have it installed in a custom directory - the extensions won't be available in directory referenced in above answers.
Try right-clicking on Chrome's shortcut & Check the "Target" directory. From there, navigate to one directory above and you should be able to see the User Data folder and then can use the answers mentioned above

Related

Unable to modify value of "prompt_for_download" in chrome preferences file

Gurus,
I am using uipath(A Ui Based Automation Tool) to download a file from a website using chrome browser.
I want browser to not prompt before downloading and just download the file in the downloads folder.
From various posts on this website i found that there exists a file called "preferences" which can be modified to solve this problem.
Before coding further i decided to do the changes in the "preferences" file manually on multiple machines, just to make sure that the changes i do in the preferences file reflect in the chrome browser as well .
I am manually modifying values for these 2 options in the preferences file.
download.default_directory
download.prompt_for_download
When i changed value for download.default_directory(Manually in Preferences file), it reflects the same in the chrome browser settings on every machine that i tested on.
But When i change value for download.prompt_for_download, it reflected in the chrome browser settings on some of the machines while on others i found that it does not reflect in the browser and rather the preferences file also seems to have reverted back to previous values.
The steps i followed are as below..
close any running instance of chrome
do the modifications in the preference file and save it
open chrome and go to settings>advance and downloads
i see DreamCatcher pointing to a similiar situation in this post, but no answers there..
I hope I can help solve your issue or at least give you some direction :)
Option#1: Chrome Settings
Wouldn't the problem be solved by changing the settings for downloads in the browser before running the bot? https://support.google.com/chrome/answer/95759?co=GENIE.Platform%3DDesktop&hl=en
Option#2: Do it in UiPath
And the other thing, is that when the prompt (to save the file) appears, couldn't you insert the path of the file that includes the default folder to save + name file + extension? (e.g. on the save path of the prompt, use type text "c:\myDocuments\downloads\filename.ext" ? I've done this in the past with UiPath...get the prompt window, type text and just modify the string being passed to carry the path, file name and extensio...then click "SAVE" or use hotkey "Enter"(if the file requires replacement, these are another 20cents you will have to program in UiPath, but it'd doable).
Option#3: Script
Another option, which I have not done, but see my friends do is creating BAT files to reset certain browser settings or the "registry"...so what they do is that they configure the BAT to do the changes to the browser and they add an activity (in UiPath) to invoke the BAT file every time the browser is opened by the robot.
Links for reference:
https://superuser.com/questions/59465/is-it-possible-to-download-using-the-windows-command-line
https://getadmx.com/?Category=Chrome&Policy=Google.Policies.Chrome::DownloadDirectory

How does Windows link HTML files to folders?

Almost every time you save a web page from a web browser to your local computer a PAGENAME.html (or .htm) file is created and a folder named 'PAGENAME_files' that contains resources specific to that page.
If you copy/move/delete either the folder or the .html file Windows automatically does the same operation the other file as well.
This behaviour also happens if you create a file named 1.html and a folder called 1_files.
How does this link happen? And why does it work only with web files?
This is a shell feature, not a file system feature. The shell copy engine just looks for a folder with the same name (plus a localized suffix) when copying/moving .htm[l] files.
This feature is called Connected Files and is documented here.
It's a built-in linkage in Windows.
Open up Explorer (not IE, Windows), Tools, Options, View, then in Advanced Settings there'll be a "Managing pairs of Web pages and folders" section.
If people are stuck and ended up here to find how to unlink, here's an easy trick : on Windows 10, I couldn't find how to unlink a .html file from its associated media folder, so I deleted both of them, and in the bin I restored only the .html file and it was then restored and unlinked from its folder.
It is a good question.
Under Windows 7 I managed to solve forced links by simply renaming the file.
I think it is the easiest way.

Can't upload chrome extension--.json file not selectable

So, I'm going through Steven Foote's "Learning How to Program" book and the beginning section has us uploading a manifest.json file to chrome://extensions. Using http://jsonlint.com/, the code seems valid.
When I go to upload the .json file to the extension page, it is unselectable (can't click on the file")
http://i.imgur.com/XbGeTpB.png
Any suggestions?
Thanks.
A manifest JSON file is useless by itself - it describes how to handle the rest of the content in the folder.
Which is why, in fact, you need to select the folder (that contains the manifest) to load as an unpacked extension.
You'll notice that the dialog in your screenshot asks for exactly that and the "Select" button is active even though you haven't selected any files. You're in the target directory and there's nothing extra you need to do.
And if, later, you publish to CWS, you'll need to provide a zip of your extension folder.

Convert json formatted Chrome bookmark file into html

How can I convert json formatted bookmarks file (taken from /Library/Application Support/Google/Chrome/Default/Bookmarks) into an bookmarks html file so Google Chrome can import it?
This has more or less been answered in comments by #Mr.P, but let me formalise:
In my example I have a current (OS root) drive called C:\\. I have a storage drive of F:\\ which has a previous install of Chrome on it which I want to retrieve the bookmarks from.
I did this in Powershell but you could easily do it in file explorer you would just need to either enter the path to <drive_name>:\\users\<account_name>\appdata manually/show hidden folders.
close all instances of Chrome currently running (maybe check in the process monitor to ensure all processes terminated).
navigate to <storage_drive_letter>:\\users\<account_name>\appdata\local\google\chrome\default.
On PowerShell you would select the previous install bookmarks file by entering $books = Get-Item bookmarks. On file explorer you would 'cut'
cd <os_drive_letter>:\\users\<account_name>\appdata\local\google\chrome\default or navigate to this path on file explorer
mv $books . or paste file
open up Chrome again and check the bookmarks: they should be visible all together.
[optional] If you're brave close all Chrome windows once again (potentially save both files somewhere else before you do this) delete all files with 'bookmarks' at the start (you can use gci | where {$_.name -like "bookmarks"} | rm) then reopen the browser. In your filesystem Chrome should have automatically regenerated the bookmarks into one file.
If this doesn't work for other people let me know
If for whatever reason, you only have the JSON output of the Chrome bookmarks file, don't sweat it. Chrome will export bookmarks as HTML and import as HTML. But, sometimes you don't have the luxury of exporting from Chrome because of some issue with your Windows installation. But, you're resourceful and managed to at least get access to your Windows filesystem and backed up your Chrome bookmarks file. But, now how do you import it to Chrome on a working computer without it being in HTML format?
On Windows (this was tested on Win 10), all you have to do is Show Hidden Files and Folders and then paste and overwrite the Bookmarks file at:
C:\Users\YourUserName\AppData\Local\Google\Chrome\User Data\Default
Don't run around in circles trying to convert JSON to HTML if you have a Windows computer. I'm not sure about Mac and Linux, but I'd bet it would work similarly.
Folder location of bookmark (on February 2021)
Chrome: %LOCALAPPDATA%\Google\Chrome\User Data\Default
Edge: %LOCALAPPDATA%\Microsoft\Edge\User Data\Default
Note: "Default" could be something else (e.g. Profile 1) if you are not currently logged in.
Finally i found it
Step 1: Goto Run --> enter - appdata to navigate to this folder
Step 2: You Needs to take backup/copy of your old bookmarks and keep it one place
Step 3 : then you need to navigate to below folder, you can find many profiles of yours.
Navigate to the needed gmail account profile which has your display pic or profile pic
[identify the account you want to import bookmarks]
Go back to the profile 12 [the account which i want to see the bookmarks]
Then replace your old bookmark file here[step 2:which you taken backup bookmark file]
Boooooom! just restart chrome
I think you are making this harder than it is. Save the JASON bookmark.file, first. Go to C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default to save the Bookmark.file somewhere on your computer. Then uninstall the browser (Chrome, for example). Make sure you check the box to remove all history, etc. before you click on Uninstall.
Reinstall the browser, then overwrite the Bookmark.file in C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default
DONE! Bookmarks restored. No need to save bookmark.file or convert it to an HTML file for restoral. Just overwrite the bookmark.file with the one you saved before uninstall of your browser.
If you're worried about modifying existing programs, or overwriting any other bookmarks you've currently got, then I found the following easiest:
Install a portable version of Chrome, for example from portableapps.com
Navigate to App\DefaultData\profile\Default inside the install directory
Replace the Bookmarks file with your json file
Launch Chrome Portable, and export the bookmarks as html
Delete Chrome Portable
I had same problem with opera. I simply copy pasted that json file into new location of new installation.
Just drag the .json to opened firefox window and the run bookmarklet
(create new bookmark, enter code in location)
CODE: SELECT ALL
javascript:(function(){var E=document.getElementsByTagName('PRE')[0],T=E.innerHTML,i=0,r1,r2;t=new Array();while(/("uri":"([^"]*)")/g.exec(T)){r1=RegExp.$1;r2=RegExp.$2;if(/^https?:/.exec(r2)){t[i++]='['+(i)+']:'+r2+'</a>';}}with(window.open().document){for(i=0;t[i];i++)write(t[i]+'');close();}})();
Thanks to dickvl
Clickable links result
Save webpage complete will save .htm
Save .json to desktop, drag browser window smaller from lower right edge till you can drag the .json into opened window., doubleclick titlebar to restore browser full size. In the tab that opens with .json data, click the bookmarklet. Another tab should open with links. You can save as .htm by right click "save page as" web page complete.
Anywhere in the opened window, like dragging a shortcut or html, it'll open
You can also do File > Open File > browse to .json > open
Using JSON
Backup your bookmarks as a JSON file.
Delete the bookmarks you do not want.
Export the ones you do want as an HTML file
Restore your bookmarks with the JSON file
To add mor in the JSON file in a text editor.
Create rows by finding and replacing ',{"title' with 'return{"title' (Don't type the single quotes and, in the replace field, use the appropriate substitute for return: ¶ or \r, for example. My search looked like this: Find: ,{"title Replace: \r,{"title Replace All gave me rows instead of a continuous stream of text.
Save the file as text and open it in a spreadsheet. Each bookmark will have its own row. The site name, URLs, and other data are in columns.
Create a bookmark by copying the URL, pasting it into Firefox, and going to the website.
Drag the URL from the toolbar to the desired location in the sidebar. Change the bookmark title if you don't like the website-assigned title.
Repeat as needed.

Chrome Extension - Invalid Package. Details:Can't unzip the extension

I worked on a chrome extension and uploaded it to chrome webstore and everything went well, I installed it on my Mac and on my Ubuntu machines in chrome it worked fine and installed. But when I try it on Windows machines, after download it popups a error message saying "Invalid Package, Can't unzip the extension".
Can any one tell me why or what might be the cause for this OS specific issue. Does it have anything to do with the permission or anything with respective folder name or content? The folder name or the extension name don't have any special characters and the previous version was fine.
Thanks in advance.
This is because there a file inside the package with a Windows invalid character in name or there a corrupted file. In my case I've tried to download the CouponsHelper extension and this error was displayed too.
I downloaded the CRX file manually and opened it with 7Zip. In the folder had a file named Icon. When I try to extract using 7Zip an error occurs too.
Note on the screenshot that there an invalid char in Icon file and that it is zero sized (possibly corrupted).
Another cause of this problem (Error: could not unzip extension) might be that you include the root directory in your zip.
You should zip all files in the same level of manifest.json.
Example
-yourappfolder
|_manifest.js
|_popup.html
In this case you should zip only manifest.js and popup.html, instead of zip the entire directory yourappfolder.
In other words, in your zip file you should NOT see the yourappfolder directory.
So the trick it to compress all the files within the folder not the folder itself.
NOTE: If it's saved in Google Drive (local syncing) this well mess it up too. Drive attaches little icons to folders that show up as unknown.
So remake the folder outside of Google Drive.
That's what was messing mine up after the "only compress inside of folder" fix.
I had the same problem but the reason was different.
I found that there is an image which has a name that is too long. When I replaced the name with a shorter one and built new package, it installed successfully.
I hope this helps anyone may facing the same problem.
A quick Google only turned up one possibly useful result but I wasn't sure if it would help.
Is that error message exactly what you see (i.e. word for word)? I couldn't find it in the code.
I may be wrong but I think this could be the code responsible for the error. Unfortunately, the zip::Unzip call can potentially fail for a number of reasons and only provides more details in the logs. I'm guessing such logs output to this location (Windows XP);
%USERPROFILE%\Local Settings\Application Data\Google\Chrome\Application\debug.log
None of this information may be useful to you but I thought I'd show you my investigation :)
Have you tried to install the extension again and do you have administration rights (not sure if this would have an affect here)?
I had the same problem but it was rejecting it because either the file was too big or the paths were too long (Windows...), which was because I accidentally included my entire node_modules directory in the .crx file.
It could be caused by a lot of things.
For me, the problem was having .xcf (Gimp) files inside the package.
The extension loaded fine when unzipped manually but showed the "couldn't unzip" error in when loaded from the Chrome Webstore.
I had problems with zipping with MacOS. There was a bunch of hidden files in the zip.
Using Windows solved it but probably taking not the default zipper in MacOS should do the same.
I had a similar problem.
My solution was:
unzip the CRX to a directory...lets say called freddy123
Rename "_manifest" to "manifest"..i.e remove the underscore.
Chrome->settings->More Tools->Extensions (Check Develop Mode Check box)
Load Unpacked extension (select freddy123 directory)
This worked for me.