我需要列出Firefox扩展中保存的网站登录名(无密码),对我来说,最简单的方法是获取Firefox用户配置文件目录的路径并解析logins.json
。似乎扩展API不包含此属性。我发现只有one link告诉我可以通过通过Native Messaging与Native 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);
...并将其传递给扩展名。
在扩展程序中是否还有其他方法可以获取凭据登录?