fix: crash when loadExtension fails (#27561)
This commit is contained in:
parent
20a71be849
commit
b6df7cd327
3 changed files with 29 additions and 15 deletions
|
@ -112,7 +112,6 @@ void ElectronExtensionLoader::FinishExtensionLoad(
|
|||
scoped_refptr<const Extension> extension = result.first;
|
||||
if (extension) {
|
||||
extension_registrar_.AddExtension(extension);
|
||||
}
|
||||
|
||||
// Write extension install time to ExtensionPrefs. This is required by
|
||||
// WebRequestAPI which calls extensions::ExtensionPrefs::GetInstallTime.
|
||||
|
@ -126,8 +125,9 @@ void ElectronExtensionLoader::FinishExtensionLoad(
|
|||
extensions::pref_names::kPrefPreferences);
|
||||
auto preference = update.Create();
|
||||
const base::Time install_time = base::Time().Now();
|
||||
preference->SetString("install_time",
|
||||
base::NumberToString(install_time.ToInternalValue()));
|
||||
preference->SetString(
|
||||
"install_time", base::NumberToString(install_time.ToInternalValue()));
|
||||
}
|
||||
}
|
||||
|
||||
std::move(cb).Run(extension.get(), result.second);
|
||||
|
|
|
@ -107,6 +107,12 @@ describe('chrome extensions', () => {
|
|||
expect(bg).to.equal('red');
|
||||
});
|
||||
|
||||
it('does not crash when failing to load an extension', async () => {
|
||||
const customSession = session.fromPartition(`persist:${uuid.v4()}`);
|
||||
const promise = customSession.loadExtension(path.join(fixtures, 'extensions', 'load-error'));
|
||||
await expect(promise).to.eventually.be.rejected();
|
||||
});
|
||||
|
||||
it('serializes a loaded extension', async () => {
|
||||
const extensionPath = path.join(fixtures, 'extensions', 'red-bg');
|
||||
const manifest = JSON.parse(fs.readFileSync(path.join(extensionPath, 'manifest.json'), 'utf-8'));
|
||||
|
|
8
spec-main/fixtures/extensions/load-error/manifest.json
Normal file
8
spec-main/fixtures/extensions/load-error/manifest.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"name": "load-error",
|
||||
"version": "1.0",
|
||||
"icons": {
|
||||
"16": "/images/error.png"
|
||||
},
|
||||
"manifest_version": 2
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue