can you tell me, how can I generate Chrome Extensions in Java code, that is how can I create .crx file in Java code?
Firstly, I created the simplest Chrome Extensions manually. In short, it was done like this:
(1) I created a folder, for example "extension". And created inside 2 files: manifest.json and webrequest.js.
(2) The content of manifest.json is:
{
"manifest_version": 2,
"name": "Webrequest",
"version": "1.0",
"description": "Extension",
"permissions": [
// ...
],
"background": {
"scripts": [
"webrequest.js"
]
}
}
(3) The content of webrequest.js is:
chrome.webRequest.onAuthRequired.addListener(
function (details) {
console.log("onAuthRequired event has fired", details);
return {
authCredentials: {
username: "user1",
password: "pswd1"
}
};
},
{
urls: [
// ...
]
},
[
"blocking"
]
);
Here, in the authCredentials section, specify the required username / password.
(4) Then in the Chrome browser I wrote "chrome://extensions". Then go into the extensions. Turn on "Developer mode". Next, "Pack extension", and specify my "extension" folder. As a result, Chrome created 2 files: extension.crx and extension.pem.
In the Java project, in the resources folder, I created the chrome_extensions directory and copied the extension.crx file there.
(5) Next in the code, I added my extension:
final String fileString = classLoader.getResource("chrome_extensions/extension.crx").getFile();
final File extensionFile = new File(fileString);
options.addExtensions(extensionFile);
In the end, everything works for me. But the problem is: as you can see in paragraph (3), I use the login and password of a specific user. But I actually have a lot of users, about 10. So I have 2 options:
Either create 10 .crx files with different login / passwords,
or generate a .crx file directly in the Java code. I want to try second way.
I already tried to find in Google my question. But I only find the case of how to create a function generateCrxHeader(byte [] extensionContents) from the zip archive. It seems to me, that this is not my situation.
I need to generate the final .crx file, having 2 files at the very beginning: manifest.json and webrequest.js. And I must first substitute the current username and password in webrequest.js.
Can you help me, please, how can I do this?
question from:
https://stackoverflow.com/questions/65841814/how-can-i-generate-chrome-extensions-in-java-code