C# 如何使用木偶手来获得表演的价值。时间来源?
使用PuppeterSharep,我尝试使用下面的C代码获取C# 如何使用木偶手来获得表演的价值。时间来源?,c#,google-chrome-devtools,puppeteer,puppeteer-sharp,C#,Google Chrome Devtools,Puppeteer,Puppeteer Sharp,使用PuppeterSharep,我尝试使用下面的C代码获取performance.timeOrigin值: JToken performanceTimeOriginString = await _page.EvaluateFunctionAsync("JSON.stringify(performance.timeOrigin);").ConfigureAwait(false); 我已经在JavaScript控制台中验证了这一点: 但是,当我运行上面的PuppeterSharp代码时,我得到
performance.timeOrigin
值:
JToken performanceTimeOriginString = await _page.EvaluateFunctionAsync("JSON.stringify(performance.timeOrigin);").ConfigureAwait(false);
我已经在JavaScript控制台中验证了这一点:
但是,当我运行上面的PuppeterSharp代码时,我得到以下异常:
System.AggregateException: One or more errors occurred. (Evaluation failed: SyntaxError: Unexpected token ';') ---> PuppeteerSharp.EvaluationFailedException: Evaluation failed: SyntaxError: Unexpected token ';'
at PuppeteerSharp.ExecutionContext.ExecuteEvaluationAsync(String method, Object args)
at PuppeteerSharp.ExecutionContext.RemoteObjectTaskToObject[T](Task`1 remote)
at PuppeteerSharp.DOMWorld.EvaluateFunctionAsync[T](String script, Object[] args)
--- End of inner exception stack trace ---
它告诉我删除分号(非常奇怪),所以我尝试了一下,但得到了下面的例外
System.AggregateException: One or more errors occurred. (Protocol error (Runtime.callFunctionOn): Given expression does not evaluate to a function) ---> PuppeteerSharp.EvaluationFailedException: Protocol error (Runtime.callFunctionOn): Given expression does not evaluate to a function ---> PuppeteerSharp.MessageException: Protocol error (Runtime.callFunctionOn): Given expression does not evaluate to a function
at PuppeteerSharp.CDPSession.SendAsync(String method, Object args, Boolean waitForCallback)
at PuppeteerSharp.CDPSession.SendAsync[T](String method, Object args)
at PuppeteerSharp.ExecutionContext.ExecuteEvaluationAsync(String method, Object args)
--- End of inner exception stack trace ---
我如何使用PuppeterSharep来获取性能值。timeOrigin?您应该使用
EvaluateExpressionAsync
_page.EvaluateExpressionAsync("JSON.stringify(performance.timeOrigin)").ConfigureAwait(false);
您应该使用
EvaluateExpressionAsync
_page.EvaluateExpressionAsync("JSON.stringify(performance.timeOrigin)").ConfigureAwait(false);