Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream or expose profile creation + extension installed #2439

Closed
fregante opened this issue Jun 16, 2022 · 4 comments
Closed

Upstream or expose profile creation + extension installed #2439

fregante opened this issue Jun 16, 2022 · 4 comments

Comments

@fregante
Copy link
Contributor

firefox-profile offers a flag to install an extension in the profile but it doesn't work:

web-ext uses this module but then it takes care of installing the extension manually:

export async function installExtension(
{
asProxy = false,
manifestData,
profile,
extensionPath,
asyncFsStat = defaultAsyncFsStat,
}: InstallExtensionParams): Promise<any> {
// This more or less follows
// https://github.com/saadtazi/firefox-profile-js/blob/master/lib/firefox_profile.js#L531
// (which is broken for web extensions).
// TODO: maybe uplift a patch that supports web extensions instead?
if (!profile.extensionsDir) {
throw new WebExtError('profile.extensionsDir was unexpectedly empty');
}
try {
await asyncFsStat(profile.extensionsDir);
} catch (error) {
if (isErrorWithCode('ENOENT', error)) {
log.debug(`Creating extensions directory: ${profile.extensionsDir}`);
await fs.mkdir(profile.extensionsDir);
} else {
throw error;
}
}
const id = getManifestId(manifestData);
if (!id) {
throw new UsageError(
'An explicit extension ID is required when installing to ' +
'a profile (applications.gecko.id not found in manifest.json)');
}
if (asProxy) {
log.debug(`Installing as an extension proxy; source: ${extensionPath}`);
const isDir = await isDirectory(extensionPath);
if (!isDir) {
throw new WebExtError(
'proxy install: extensionPath must be the extension source ' +
`directory; got: ${extensionPath}`);
}
// Write a special extension proxy file containing the source
// directory. See:
// https://developer.mozilla.org/en-US/Add-ons/Setting_up_extension_development_environment#Firefox_extension_proxy_file
const destPath = path.join(profile.extensionsDir, `${id}`);
const writeStream = nodeFs.createWriteStream(destPath);
writeStream.write(extensionPath);
writeStream.end();
return await fromEvent(writeStream, 'close');
} else {
// Write the XPI file to the profile.
const readStream = nodeFs.createReadStream(extensionPath);
const destPath = path.join(profile.extensionsDir, `${id}.xpi`);
const writeStream = nodeFs.createWriteStream(destPath);
log.debug(`Installing extension from ${extensionPath} to ${destPath}`);
readStream.pipe(writeStream);
return await Promise.all([
fromEvent(readStream, 'close'),
fromEvent(writeStream, 'close'),
]);
}
}

Would it be possible to upstream this ability or at least to expose it so that web-ext can be used while testing without having it run Firefox directly? This is useful for testing setups, which are currently are mess for Firefox because there's no easy way to install extensions programmatically.

This is the best solution I found:

  1. Use web-ext run to open Firefox with the extension
  2. Point puppeteer to its dev server

Puppeteer offers its own way to run Firefox and, if I could just use web-ext to create the profile, I'd just need to specify a single flag like I do for Chrome

@fregante
Copy link
Contributor Author

I just remembered that Firefox requires a live RDP call to install the extension, which means this isn't really practical either.

async installTemporaryAddon(
addonPath: string
): Promise<FirefoxRDPResponseAddon> {
const addonsActor = await this.getAddonsActor();
try {
const response = await this.client.request({
to: addonsActor,
type: 'installTemporaryAddon',
addonPath,
});
log.debug(`installTemporaryAddon: ${JSON.stringify(response)}`);
log.info(`Installed ${addonPath} as a temporary add-on`);
return response;
} catch (err) {
const message = requestErrorToMessage(err);
throw new WebExtError(`installTemporaryAddon: Error: ${message}`);
}
}

Can anyone in Mozilla make the process of testing web extensions less painful? With Chrome I just need a single command line option and Firefox should allow the same thing.

@fregante
Copy link
Contributor Author

fregante commented Jun 16, 2022

@fregante fregante closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2022
@christian-bromann
Copy link

@fregante can we maybe re-open this? I've build this package and am interested in offering the ability to easily load an extension from an xpi file or fs path before the browser starts. It would be awesome if this package could simplify the creation of Firefox profiles.

@fregante
Copy link
Contributor Author

Interest in this has already been expressed in #1927 (comment)

It's best to continue there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants