Skip to content

Commit 7262801

Browse files
kblokclaude
andauthored
feat: add Path and Enabled metadata to Extension class (upstream PR #14870) (#3427)
Implements puppeteer/puppeteer#14870 which adds `path` and `enabled` properties to the Extension API, exposing the file system path and enabled state of installed browser extensions. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 07bae27 commit 7262801

5 files changed

Lines changed: 52 additions & 4 deletions

File tree

lib/PuppeteerSharp.Tests/ExtensionsTests/ExtensionsTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,35 @@ public async Task CanEvaluateInTheServiceWorker()
4141
var worker = await serviceWorkerTarget.WorkerAsync();
4242
Assert.That(await worker.EvaluateFunctionAsync<int>("() => globalThis.MAGIC"), Is.EqualTo(42));
4343
}
44+
45+
[Test, PuppeteerTest("extensions.spec", "extensions", "should list extensions and their properties")]
46+
public async Task ShouldListExtensionsAndTheirProperties()
47+
{
48+
var options = new LaunchOptions
49+
{
50+
Headless = false,
51+
EnableExtensions = true,
52+
Pipe = true,
53+
};
54+
55+
await using var browser = await Puppeteer.LaunchAsync(options, TestConstants.LoggerFactory);
56+
57+
var extensionId = await browser.InstallExtensionAsync(_extensionPath);
58+
59+
await browser.WaitForTargetAsync(t =>
60+
t.Url.Contains(extensionId) && t.Type == TargetType.ServiceWorker);
61+
62+
var extensions = await browser.GetExtensionsAsync();
63+
var extension = extensions[extensionId];
64+
65+
Assert.That(extension, Is.Not.Null);
66+
Assert.That(extension.Name, Is.EqualTo("Simple extension"));
67+
Assert.That(extension.Version, Is.EqualTo("0.1"));
68+
Assert.That(extension.Path, Is.EqualTo(_extensionPath));
69+
Assert.That(extension.Enabled, Is.True);
70+
Assert.That(extension.Id, Is.EqualTo(extensionId));
71+
72+
await browser.UninstallExtensionAsync(extensionId);
73+
}
4474
}
4575
}

lib/PuppeteerSharp/Cdp/CdpBrowser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public override async Task<IReadOnlyDictionary<string, Extension>> GetExtensions
238238
}
239239
else
240240
{
241-
extensionsMap[info.Id] = new CdpExtension(info.Id, info.Version, info.Name, this);
241+
extensionsMap[info.Id] = new CdpExtension(info.Id, info.Version, info.Name, info.Path, info.Enabled, this);
242242
}
243243
}
244244

lib/PuppeteerSharp/Cdp/CdpExtension.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ internal class CdpExtension : Extension
1212
{
1313
private readonly CdpBrowser _browser;
1414

15-
internal CdpExtension(string id, string version, string name, CdpBrowser browser)
16-
: base(id, version, name)
15+
internal CdpExtension(string id, string version, string name, string path, bool enabled, CdpBrowser browser)
16+
: base(id, version, name, path, enabled)
1717
{
1818
_browser = browser;
1919
}

lib/PuppeteerSharp/Cdp/Messaging/ExtensionInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@ internal class ExtensionInfo
77
public string Version { get; set; }
88

99
public string Name { get; set; }
10+
11+
public string Path { get; set; }
12+
13+
public bool Enabled { get; set; }
1014
}
1115
}

lib/PuppeteerSharp/Extension.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ public abstract class Extension
1717
/// <param name="id">The extension ID.</param>
1818
/// <param name="version">The extension version.</param>
1919
/// <param name="name">The extension name.</param>
20-
protected Extension(string id, string version, string name)
20+
/// <param name="path">The file system path of the extension.</param>
21+
/// <param name="enabled">Whether the extension is enabled.</param>
22+
protected Extension(string id, string version, string name, string path, bool enabled)
2123
{
2224
Id = id;
2325
Version = version;
2426
Name = name;
27+
Path = path;
28+
Enabled = enabled;
2529
}
2630

2731
/// <summary>
@@ -39,6 +43,16 @@ protected Extension(string id, string version, string name)
3943
/// </summary>
4044
public string Name { get; }
4145

46+
/// <summary>
47+
/// Gets the path in the file system where the extension is located.
48+
/// </summary>
49+
public string Path { get; }
50+
51+
/// <summary>
52+
/// Gets a value indicating whether the extension is enabled.
53+
/// </summary>
54+
public bool Enabled { get; }
55+
4256
/// <summary>
4357
/// Returns the list of the currently active service workers of the extension.
4458
/// </summary>

0 commit comments

Comments
 (0)