NullReferenceException in Page.AddConsoleMessageAsync
See original GitHub issueThe exception is thrown when I call Page.WaitForSelectorAsync, but it looks like the actual issue is that something is being logged to the console that PuppeteerSharp can’t handle correctly:
PuppeteerSharp.TargetClosedException: 'Protocol error(Runtime.callFunctionOn): Target closed. (Page failed to process Runtime.consoleAPICalled. Object reference not set to an instance of an object.. at PuppeteerSharp.Page.<>c.<AddConsoleMessageAsync>b__262_1(IJSHandle i) in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\Page.cs:line 1672
at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
at System.String.JoinCore[T](ReadOnlySpan`1 separator, IEnumerable`1 values)
at System.String.Join[T](String separator, IEnumerable`1 values)
at PuppeteerSharp.Page.AddConsoleMessageAsync(ConsoleType type, IJSHandle[] values, StackTrace stackTrace) in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\Page.cs:line 1685
at PuppeteerSharp.Page.Client_MessageReceived(Object sender, MessageEventArgs e) in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\Page.cs:line 1471)'
This is reproducible on both PuppeteerSharp v8 and v9, running on .NET 7. Not sure I can share a repro case since the page I’m accessing requires authentication. When I look at the console for the page in question, I see some uncaught TypeErrors, e.g.:
Issue Analytics
- State:
- Created 8 months ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
NullReferenceException on page initialization if I use ...
Your page is trying to render @pageGlobal.Title , before it's even got it from the async method. That's why if you do pageGlobal...
Read more >puppeteer-sharp/lib/PuppeteerSharp/Page.cs at master
Url, AddConsoleMessageAsync, HandleException); _workers[sessionId] = worker; WorkerCreated?.Invoke(this, new WorkerEventArgs(worker)); } if (target.
Read more >Null Reference Exception in Blazor Router - Matthew Champion
So this is a bit speculative, but I believe that the NullReferenceException is thrown in circumstances where the router is unable to correctly ......
Read more >Object reference not set to an instance of an object | Page 2
A null reference means that it is trying to access something that doesn't exist. You either forgot to drag something in the editor,...
Read more >NullReferenceException Class (System)
The exception that is thrown when there is an attempt to dereference a null object reference.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kblok The
JTokenType.Object
check added in #2025, was there a reason to check theJToken
type rather thanRemoteObjectType.Object
?Calling
console.debug(null);
results in an exception with a callstack similar to this one.Checking
RemoteObject.Type == RemoteObjectType.Object
resolves the exception. Argubily passingnull
toconsole.debug
is pointless. Nonetheless it shouldn’t crash.,9.0.1 looks good, thanks!