Skip to content

Commit a089150

Browse files
kblokclaude
andcommitted
fix: remove invalid event access from subclass; fix describe chain
- Remove if (Console != null) check in CdpWebWorker since events can only be accessed from their declaring class (CS0070) - Fix PuppeteerTest describe chain from 'Workers > console' to 'Workers console' Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 64045bc commit a089150

2 files changed

Lines changed: 34 additions & 37 deletions

File tree

lib/PuppeteerSharp.Tests/WorkerTests/PageWorkerTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public async Task CanBeClosed()
143143
Assert.That(await workerClosedTcs.Task, Is.SameAs(worker));
144144
}
145145

146-
[Test, PuppeteerTest("worker.spec", "Workers > console", "should work")]
146+
[Test, PuppeteerTest("worker.spec", "Workers console", "should work")]
147147
public async Task ConsoleShouldWork()
148148
{
149149
var worker = await CreateWorkerAsync();
@@ -160,7 +160,7 @@ public async Task ConsoleShouldWork()
160160
Assert.That(await message.Args[1].JsonValueAsync<int>(), Is.EqualTo(5));
161161
}
162162

163-
[Test, PuppeteerTest("worker.spec", "Workers > console", "should work for Error instances")]
163+
[Test, PuppeteerTest("worker.spec", "Workers console", "should work for Error instances")]
164164
public async Task ConsoleShouldWorkForErrorInstances()
165165
{
166166
var worker = await CreateWorkerAsync();
@@ -175,7 +175,7 @@ public async Task ConsoleShouldWorkForErrorInstances()
175175
Assert.That(message.Args, Has.Count.EqualTo(1));
176176
}
177177

178-
[Test, PuppeteerTest("worker.spec", "Workers > console", "should return the first line of the error message in text()")]
178+
[Test, PuppeteerTest("worker.spec", "Workers console", "should return the first line of the error message in text()")]
179179
public async Task ConsoleShouldReturnFirstLineOfErrorMessageInText()
180180
{
181181
var worker = await CreateWorkerAsync();
@@ -189,7 +189,7 @@ public async Task ConsoleShouldReturnFirstLineOfErrorMessageInText()
189189
Assert.That(message.Type, Is.EqualTo(ConsoleType.Log));
190190
}
191191

192-
[Test, PuppeteerTest("worker.spec", "Workers > console", "should work for console.trace")]
192+
[Test, PuppeteerTest("worker.spec", "Workers console", "should work for console.trace")]
193193
public async Task ConsoleShouldWorkForConsoleTrace()
194194
{
195195
var worker = await CreateWorkerAsync();
@@ -203,7 +203,7 @@ public async Task ConsoleShouldWorkForConsoleTrace()
203203
Assert.That(message.Text, Is.EqualTo("calling console.trace"));
204204
}
205205

206-
[Test, PuppeteerTest("worker.spec", "Workers > console", "should work for console.dir")]
206+
[Test, PuppeteerTest("worker.spec", "Workers console", "should work for console.dir")]
207207
public async Task ConsoleShouldWorkForConsoleDir()
208208
{
209209
var worker = await CreateWorkerAsync();
@@ -217,7 +217,7 @@ public async Task ConsoleShouldWorkForConsoleDir()
217217
Assert.That(message.Text, Is.EqualTo("calling console.dir"));
218218
}
219219

220-
[Test, PuppeteerTest("worker.spec", "Workers > console", "should work for console.warn")]
220+
[Test, PuppeteerTest("worker.spec", "Workers console", "should work for console.warn")]
221221
public async Task ConsoleShouldWorkForConsoleWarn()
222222
{
223223
var worker = await CreateWorkerAsync();
@@ -231,7 +231,7 @@ public async Task ConsoleShouldWorkForConsoleWarn()
231231
Assert.That(message.Text, Is.EqualTo("calling console.warn"));
232232
}
233233

234-
[Test, PuppeteerTest("worker.spec", "Workers > console", "should work for console.error")]
234+
[Test, PuppeteerTest("worker.spec", "Workers console", "should work for console.error")]
235235
public async Task ConsoleShouldWorkForConsoleError()
236236
{
237237
var worker = await CreateWorkerAsync();
@@ -245,7 +245,7 @@ public async Task ConsoleShouldWorkForConsoleError()
245245
Assert.That(message.Text, Is.EqualTo("calling console.error"));
246246
}
247247

248-
[Test, PuppeteerTest("worker.spec", "Workers > console", "should work for console.log with promise")]
248+
[Test, PuppeteerTest("worker.spec", "Workers console", "should work for console.log with promise")]
249249
public async Task ConsoleShouldWorkForConsoleLogWithPromise()
250250
{
251251
var worker = await CreateWorkerAsync();
@@ -259,7 +259,7 @@ public async Task ConsoleShouldWorkForConsoleLogWithPromise()
259259
Assert.That(message.Text, Does.Contain("promise").Or.Contain("Promise"));
260260
}
261261

262-
[Test, PuppeteerTest("worker.spec", "Workers > console", "should work for different console API calls with timing functions")]
262+
[Test, PuppeteerTest("worker.spec", "Workers console", "should work for different console API calls with timing functions")]
263263
public async Task ConsoleShouldWorkForTimingFunctions()
264264
{
265265
var worker = await CreateWorkerAsync();
@@ -276,7 +276,7 @@ await worker.EvaluateFunctionAsync(@"() => {
276276
Assert.That(messages[0].Text, Does.Contain("calling console.time"));
277277
}
278278

279-
[Test, PuppeteerTest("worker.spec", "Workers > console", "should work for different console API calls with group functions")]
279+
[Test, PuppeteerTest("worker.spec", "Workers console", "should work for different console API calls with group functions")]
280280
public async Task ConsoleShouldWorkForGroupFunctions()
281281
{
282282
var worker = await CreateWorkerAsync();
@@ -294,7 +294,7 @@ await worker.EvaluateFunctionAsync(@"() => {
294294
Assert.That(messages[0].Text, Does.Contain("calling console.group"));
295295
}
296296

297-
[Test, PuppeteerTest("worker.spec", "Workers > console", "should return remote objects")]
297+
[Test, PuppeteerTest("worker.spec", "Workers console", "should return remote objects")]
298298
public async Task ConsoleShouldReturnRemoteObjects()
299299
{
300300
var worker = await CreateWorkerAsync();

lib/PuppeteerSharp/Cdp/CdpWebWorker.cs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -164,42 +164,39 @@ private async Task OnConsoleAPICalledAsync(MessageEventArgs e)
164164
var consoleData = e.MessageData.ToObject<PageConsoleResponse>();
165165
var handles = consoleData.Args.Select(i => new CdpJSHandle(World, i)).ToArray<IJSHandle>();
166166

167-
if (Console != null)
167+
var tokens = handles.Select(i =>
168168
{
169-
var tokens = handles.Select(i =>
169+
var handle = (ICdpHandle)i;
170+
if (handle.RemoteObject.Subtype == RemoteObjectSubtype.Error && !string.IsNullOrEmpty(handle.RemoteObject.Description))
170171
{
171-
var handle = (ICdpHandle)i;
172-
if (handle.RemoteObject.Subtype == RemoteObjectSubtype.Error && !string.IsNullOrEmpty(handle.RemoteObject.Description))
173-
{
174-
return handle.RemoteObject.Description.Split('\n')[0];
175-
}
172+
return handle.RemoteObject.Description.Split('\n')[0];
173+
}
176174

177-
return handle.RemoteObject.ObjectId != null || handle.RemoteObject.Type == RemoteObjectType.Object
178-
? i.ToString()
179-
: RemoteObjectHelper.ValueFromRemoteObject<object>(handle.RemoteObject)?.ToString() ?? "null";
180-
});
175+
return handle.RemoteObject.ObjectId != null || handle.RemoteObject.Type == RemoteObjectType.Object
176+
? i.ToString()
177+
: RemoteObjectHelper.ValueFromRemoteObject<object>(handle.RemoteObject)?.ToString() ?? "null";
178+
});
181179

182-
var location = new ConsoleMessageLocation();
183-
var stackTraceLocations = new List<ConsoleMessageLocation>();
184-
if (consoleData.StackTrace?.CallFrames?.Length > 0)
180+
var location = new ConsoleMessageLocation();
181+
var stackTraceLocations = new List<ConsoleMessageLocation>();
182+
if (consoleData.StackTrace?.CallFrames?.Length > 0)
183+
{
184+
foreach (var callFrame in consoleData.StackTrace.CallFrames)
185185
{
186-
foreach (var callFrame in consoleData.StackTrace.CallFrames)
186+
stackTraceLocations.Add(new ConsoleMessageLocation
187187
{
188-
stackTraceLocations.Add(new ConsoleMessageLocation
189-
{
190-
URL = callFrame.URL,
191-
LineNumber = callFrame.LineNumber,
192-
ColumnNumber = callFrame.ColumnNumber,
193-
});
194-
}
195-
196-
location = stackTraceLocations[0];
188+
URL = callFrame.URL,
189+
LineNumber = callFrame.LineNumber,
190+
ColumnNumber = callFrame.ColumnNumber,
191+
});
197192
}
198193

199-
var consoleMessage = new ConsoleMessage(consoleData.Type, string.Join(" ", tokens), handles, location, stackTraceLocations);
200-
OnConsole(new ConsoleEventArgs(consoleMessage));
194+
location = stackTraceLocations[0];
201195
}
202196

197+
var consoleMessage = new ConsoleMessage(consoleData.Type, string.Join(" ", tokens), handles, location, stackTraceLocations);
198+
OnConsole(new ConsoleEventArgs(consoleMessage));
199+
203200
await _consoleAPICalled(consoleData.Type, handles, consoleData.StackTrace).ConfigureAwait(false);
204201
}
205202

0 commit comments

Comments
 (0)