Javascript 为什么我在page.on函数上的返回未按预期工作

Javascript 为什么我在page.on函数上的返回未按预期工作,javascript,jquery,function,return,puppeteer,Javascript,Jquery,Function,Return,Puppeteer,在我下面的Puppeter/javascript代码中,我收到了与预期不同的结果。我不知道为什么 我希望“myjson”值会在“price_json”中返回,但是它会从浏览器返回所有元素,正如您从实际结果中看到的那样 我不确定我是否在这里缺少基本的javascript知识,但是我已经在page.evaluate上做了同样的事情,这似乎很好 代码- const price_json = await page.on('response', async (response, i) => {

在我下面的Puppeter/javascript代码中,我收到了与预期不同的结果。我不知道为什么

我希望“myjson”值会在“price_json”中返回,但是它会从浏览器返回所有元素,正如您从实际结果中看到的那样

我不确定我是否在这里缺少基本的javascript知识,但是我已经在page.evaluate上做了同样的事情,这似乎很好

代码-

const price_json = await page.on('response', async (response, i) => {
        const myjson = await response.json();
        console.log("inside of the page.on")
        console.log(myjson)
        console.log("inside (end) of the page.on")
        return myjson
  }, i);

  console.log(price_json)
预期结果-(myjson如下所示)

实际结果-(返回后的价格…)

\u事件:[对象:空原型]{响应:[AsyncFunction]},
_事件提示:1,
_maxListeners:未定义,
_关闭:错误,
_客户:
CDP会话{
_活动:
[对象:空原型]{
'Fetch.requestPaused':[函数:绑定_onRequestPaused],
'Fetch.authRequired':[函数:绑定_onAuthRequired],
'Network.requestWillBeSent':[Function:bound\u onRequestWillBeSent],
“Network.requestServedFromCache”:[函数:绑定_onRequestServedFromCache],
“Network.responseReceived”:[函数:绑定_onResponseReceived],
“Network.loadingFinished”:[函数:绑定_onLoadingFinished],
“Network.loadingFailed”:[函数:绑定_onLoadingFailed],
'Page.frameAttached':[函数],
“Page.frameNavigated':[函数],
“Page.navigatedWithinDocument':[函数],
“Page.frameDetached”:[函数],
'Page.frameStoppedLoading':[函数],
'Runtime.executionContextCreated':[函数],
“Runtime.executionContextDestroyed':[函数],
'Runtime.executionContextsCleared':[函数],
'Page.lifecycleEvent':[函数],
'Target.attachedToTarget':[函数],
'Target.detachedFromTarget':[Function],
'Page.domContentEventFired':[函数],
'Page.loadEventFired':[函数],
'Runtime.consoleAPICalled':[函数],
'Runtime.bindingCalled':[Function],
'Page.javascriptDialogOpening':[函数],
'Runtime.exceptionThrown':[函数],
'Inspector.targetCrash':[函数],
“Performance.metrics”:[函数],
'Log.entryAdded':[Function],
'Page.fileChooserOpened':[Function]},
_活动地点:28,
_maxListeners:未定义,
_回调:映射{},
_连接:
联系{
_事件:[对象],
_事件提示:4,
_maxListeners:未定义,
_网址:
“ws://127.0.0.1:58923/devtools/browser/89cbedaf-2ce2-4df8-b52b-3836987B251”,
_拉斯蒂德:87,
_回调:映射{},
_延迟:0,
_运输:[WebSocketTransport],
_会话:[映射],
_关闭:false},
_targetType:“页面”,
_会话ID:'45363630A29A7F3799E8612DDB0C79B9'},
_目标:
目标{
_目标信息:
{targetId:'FB19D7C032DE5773F35827E7AECD9082',
键入:“页面”,
标题:'https://www.****www.com.au/customers/orders',
网址:'https://www.*****www.com.au/customers/orders',
附件:对,,
browserContextId:'10EE70BFE005227DB58E3291908CB868'},
_browserContext:
浏览器上下文{
_事件:[对象:空原型]{},
_事件提示:0,
_maxListeners:未定义,
_连接:[连接],
_浏览器:[浏览器],
_id:null},
_targetId:'FB19D7C032DE5773F35827E7AECD9082',
_sessionFactory:[函数],
_忽略HttpSerrors:错误,
_默认视口:{宽度:800,高度:600},
_screenshotTaskQueue:TaskQueue{{{u-chain:[Promise]},
_pagePromise:Promise{[通知]},
_workerPromise:空,
_initializedCallback:[函数],
_初始化Promise:Promise{true},
_closedCallback:[函数],
_isClosedPromise:Promise{},
_isInitialized:true},
_键盘:
键盘{
_客户:
CDP会话{
_事件:[对象],
_活动地点:28,
_maxListeners:未定义,
_回调:映射{},
_连接:[连接],
_targetType:“页面”,
_会话ID:'45363630A29A7F3799E8612DDB0C79B9'},
_修饰符:0,
_按按键:设置{},
_鼠标:
老鼠{
_客户:
CDP会话{
_事件:[对象],
_活动地点:28,
_maxListeners:未定义,
_回调:映射{},
_连接:[连接],
_targetType:“页面”,
_会话ID:'45363630A29A7F3799E8612DDB0C79B9'},
_键盘:
键盘{u客户端:[CDPSession],_修饰符:0,_按键:Set{},
_x:1157.59375,
_y:422.09375,
_按钮:'无'},
_timeoutSettings:
TimeoutSettings{{u defaultTimeout:null,{u defaultNavigationTimeout:null},
_触摸屏:
触摸屏{
_客户:
CDP会话{
_事件:[对象],
_活动地点:28,
_maxListeners:未定义,
_回调:映射{},
_连接:[连接],
_targetType:“页面”,
_会话ID:'45363630A29A7F3799E8612DDB0C79B9'},
_键盘:
键盘{u客户端:[CDPSession],_修饰符:0,_按键:Set{},
_可访问性:
可达性{
_客户:
CDP会话{
_事件:[对象],
_活动地点:28,
_maxListeners:未定义,
_回调:映射{},
_连接:[连接],
_targetType:“页面”,
_会话ID:'45363630A29A7F3799E8612DDB0C79B9'},
_框架管理器:
框架管理器{
_活动:
[对象:空原型]{
[符号(Events.FrameManager.FrameAttached)]:[函数],
[符号(Events.FrameManager.FrameDetached)]:[函数],
[Symbol(Events.FrameManager.FrameNavigated)]:[Function]},
_事件提示:3,
_maxListeners:未定义,
_客户:
CDP会话{
{ unit_price: '$39.65',
  carton_price: '$237.92',
  stock_code: '66121' }
  _events: [Object: null prototype] { response: [AsyncFunction] },
  _eventsCount: 1,
  _maxListeners: undefined,
  _closed: false,
  _client:
   CDPSession {
     _events:
      [Object: null prototype] {
        'Fetch.requestPaused': [Function: bound _onRequestPaused],
        'Fetch.authRequired': [Function: bound _onAuthRequired],
        'Network.requestWillBeSent': [Function: bound _onRequestWillBeSent],
        'Network.requestServedFromCache': [Function: bound _onRequestServedFromCache],
        'Network.responseReceived': [Function: bound _onResponseReceived],
        'Network.loadingFinished': [Function: bound _onLoadingFinished],
        'Network.loadingFailed': [Function: bound _onLoadingFailed],
        'Page.frameAttached': [Function],
        'Page.frameNavigated': [Function],
        'Page.navigatedWithinDocument': [Function],
        'Page.frameDetached': [Function],
        'Page.frameStoppedLoading': [Function],
        'Runtime.executionContextCreated': [Function],
        'Runtime.executionContextDestroyed': [Function],
        'Runtime.executionContextsCleared': [Function],
        'Page.lifecycleEvent': [Function],
        'Target.attachedToTarget': [Function],
        'Target.detachedFromTarget': [Function],
        'Page.domContentEventFired': [Function],
        'Page.loadEventFired': [Function],
        'Runtime.consoleAPICalled': [Function],
        'Runtime.bindingCalled': [Function],
        'Page.javascriptDialogOpening': [Function],
        'Runtime.exceptionThrown': [Function],
        'Inspector.targetCrashed': [Function],
        'Performance.metrics': [Function],
        'Log.entryAdded': [Function],
        'Page.fileChooserOpened': [Function] },
     _eventsCount: 28,
     _maxListeners: undefined,
     _callbacks: Map {},
     _connection:
      Connection {
        _events: [Object],
        _eventsCount: 4,
        _maxListeners: undefined,
        _url:
         'ws://127.0.0.1:58923/devtools/browser/89cbedaf-2ce2-4df8-b52b-3836987b2521',
        _lastId: 87,
        _callbacks: Map {},
        _delay: 0,
        _transport: [WebSocketTransport],
        _sessions: [Map],
        _closed: false },
     _targetType: 'page',
     _sessionId: '45363630A29A7F3799E8612DDB0C79B9' },
  _target:
   Target {
     _targetInfo:
      { targetId: 'FB19D7C032DE5773F35827E7AECD9082',
        type: 'page',
        title: 'https://www.****.com.au/customers/orders',
        url: 'https://www.*****.com.au/customers/orders',
        attached: true,
        browserContextId: '10EE70BFE005227DB58E3291908CB868' },
     _browserContext:
      BrowserContext {
        _events: [Object: null prototype] {},
        _eventsCount: 0,
        _maxListeners: undefined,
        _connection: [Connection],
        _browser: [Browser],
        _id: null },
     _targetId: 'FB19D7C032DE5773F35827E7AECD9082',
     _sessionFactory: [Function],
     _ignoreHTTPSErrors: false,
     _defaultViewport: { width: 800, height: 600 },
     _screenshotTaskQueue: TaskQueue { _chain: [Promise] },
     _pagePromise: Promise { [Circular] },
     _workerPromise: null,
     _initializedCallback: [Function],
     _initializedPromise: Promise { true },
     _closedCallback: [Function],
     _isClosedPromise: Promise { <pending> },
     _isInitialized: true },
  _keyboard:
   Keyboard {
     _client:
      CDPSession {
        _events: [Object],
        _eventsCount: 28,
        _maxListeners: undefined,
        _callbacks: Map {},
        _connection: [Connection],
        _targetType: 'page',
        _sessionId: '45363630A29A7F3799E8612DDB0C79B9' },
     _modifiers: 0,
     _pressedKeys: Set {} },
  _mouse:
   Mouse {
     _client:
      CDPSession {
        _events: [Object],
        _eventsCount: 28,
        _maxListeners: undefined,
        _callbacks: Map {},
        _connection: [Connection],
        _targetType: 'page',
        _sessionId: '45363630A29A7F3799E8612DDB0C79B9' },
     _keyboard:
      Keyboard { _client: [CDPSession], _modifiers: 0, _pressedKeys: Set {} },
     _x: 1157.59375,
     _y: 422.09375,
     _button: 'none' },
  _timeoutSettings:
   TimeoutSettings { _defaultTimeout: null, _defaultNavigationTimeout: null },
  _touchscreen:
   Touchscreen {
     _client:
      CDPSession {
        _events: [Object],
        _eventsCount: 28,
        _maxListeners: undefined,
        _callbacks: Map {},
        _connection: [Connection],
        _targetType: 'page',
        _sessionId: '45363630A29A7F3799E8612DDB0C79B9' },
     _keyboard:
      Keyboard { _client: [CDPSession], _modifiers: 0, _pressedKeys: Set {} } },
  _accessibility:
   Accessibility {
     _client:
      CDPSession {
        _events: [Object],
        _eventsCount: 28,
        _maxListeners: undefined,
        _callbacks: Map {},
        _connection: [Connection],
        _targetType: 'page',
        _sessionId: '45363630A29A7F3799E8612DDB0C79B9' } },
  _frameManager:
   FrameManager {
     _events:
      [Object: null prototype] {
        [Symbol(Events.FrameManager.FrameAttached)]: [Function],
        [Symbol(Events.FrameManager.FrameDetached)]: [Function],
        [Symbol(Events.FrameManager.FrameNavigated)]: [Function] },
     _eventsCount: 3,
     _maxListeners: undefined,
     _client:
      CDPSession {
        _events: [Object],
        _eventsCount: 28,
        _maxListeners: undefined,
        _callbacks: Map {},
        _connection: [Connection],
        _targetType: 'page',
        _sessionId: '45363630A29A7F3799E8612DDB0C79B9' },
     _page: [Circular],
     _networkManager:
      NetworkManager {
        _events: [Object],
        _eventsCount: 4,
        _maxListeners: undefined,
        _client: [CDPSession],
        _ignoreHTTPSErrors: false,
        _frameManager: [Circular],
        _requestIdToRequest: [Map],
        _requestIdToRequestWillBeSentEvent: Map {},
        _extraHTTPHeaders: {},
        _offline: false,
        _credentials: null,
        _attemptedAuthentications: Set {},
        _userRequestInterceptionEnabled: false,
        _protocolRequestInterceptionEnabled: false,
        _userCacheDisabled: false,
        _requestIdToInterceptionId: Map {} },
     _timeoutSettings:
      TimeoutSettings { _defaultTimeout: null, _defaultNavigationTimeout: null },
     _frames: Map { 'FB19D7C032DE5773F35827E7AECD9082' => [Frame] },
     _contextIdToContext: Map { 5 => [ExecutionContext], 6 => [ExecutionContext] },
     _isolatedWorlds: Set { '__puppeteer_utility_world__' },
     _mainFrame:
      Frame {
        _frameManager: [Circular],
        _client: [CDPSession],
        _parentFrame: null,
        _url: 'https://www.*****.com.au/customers/orders',
        _id: 'FB19D7C032DE5773F35827E7AECD9082',
        _detached: false,
        _loaderId: 'D87D50CD254B4D51BD687A720F36BFCA',
        _lifecycleEvents: [Set],
        _mainWorld: [DOMWorld],
        _secondaryWorld: [DOMWorld],
        _childFrames: Set {},
        _name: undefined,
        _navigationURL: 'https://www.*******.com.au/customers/orders' } },
  _emulationManager:
   EmulationManager {
     _client:
      CDPSession {
        _events: [Object],
        _eventsCount: 28,
        _maxListeners: undefined,
        _callbacks: Map {},
        _connection: [Connection],
        _targetType: 'page',
        _sessionId: '45363630A29A7F3799E8612DDB0C79B9' },
     _emulatingMobile: false,
     _hasTouch: false },
  _tracing:
   Tracing {
     _client:
      CDPSession {
        _events: [Object],
        _eventsCount: 28,
        _maxListeners: undefined,
        _callbacks: Map {},
        _connection: [Connection],
        _targetType: 'page',
        _sessionId: '45363630A29A7F3799E8612DDB0C79B9' },
     _recording: false,
     _path: '' },
  _pageBindings: Map {},
  _coverage:
   Coverage {
     _jsCoverage:
      JSCoverage {
        _client: [CDPSession],
        _enabled: false,
        _scriptURLs: Map {},
        _scriptSources: Map {},
        _eventListeners: [],
        _resetOnNavigation: false },
     _cssCoverage:
      CSSCoverage {
        _client: [CDPSession],
        _enabled: false,
        _stylesheetURLs: Map {},
        _stylesheetSources: Map {},
        _eventListeners: [],
        _resetOnNavigation: false } },
  _javascriptEnabled: true,
  _viewport: { width: 1920, height: 1080 },
  _screenshotTaskQueue:
   TaskQueue {
     _chain:
      Promise {
        <Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 07 80 00 00 04 38 08 06 00 00 00 e8 d3 c1 43 00 00 00 01 73 52 47 42 00 ae ce 1c e9 00 00 20 00 ... > } },
  _workers: Map {},
  _fileChooserInterceptionIsDisabled: false,
  _fileChooserInterceptors: Set {} }