NilkasG
(Niklas Gollenstede)
November 10, 2017, 2:41pm
2
There is no API to get the profile path, and Mozilla won’t add any either: https://bugzilla.mozilla.org/show_bug.cgi?id=1414887
That being said, under certain circumstances the location of your extension can be contained in stack traces (I don’t remember how exactly, but this definitely happed in content scripts in Firefox ~52. At the time it was a problem I had to avoid) and there is a number of more or less reliable ways to find the current profile location from within a native messaging app:
case 'firefox': {
// get the profile dir
const extId = browser.extId = process.argv[5];
if (process.env.MOZ_CRASHREPORTER_EVENTS_DIRECTORY) {
browser.profileDir = Path.resolve(process.env.MOZ_CRASHREPORTER_EVENTS_DIRECTORY, '../..');
} else {
throw new Error(`MOZ_CRASHREPORTER_EVENTS_DIRECTORY environment variable not set by Firefox`);
// either -P / -p "profile_name" or -profile "profile_path" (precedence?) default: FS.readFileSync('%AppData%\Mozilla\Firefox\profiles.ini').trim().split(/(?:\r\n?\n){2}/g).find(_=>_.includes('Default=1')).match(/Path=(.*))[1]
}
// find the extension
const extPath = Path.join(browser.profileDir, 'extensions', extId);
const [ extLink, extDir, extFile, ] = (await Promise.all([
readFile(extPath, 'utf-8').catch(() => null),
realpath(extPath).catch(() => null),
realpath(extPath +'.xpi').catch(() => null),
]));
if (extLink) { try {
const extDir = normalizeTextPath(extLink);
This file has been truncated. show original