microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.84k stars 3.67k forks source link

[BUG] playwright-core/lib/client/frame.js - Cannot read property '_object' of undefined #9882

Closed kt-vv closed 3 years ago

kt-vv commented 3 years ago

Context:

// run chrome in debug mode
exec(`google-chrome --remote-debugging-port=9222`)
// get webSocket to connect
execSync(`curl http://localhost:9222/json/version`).toString()

this._browser = await this._playwriht.connectOverCDP({wsEndpoint: wsRealEndpoint, timeout: 20000});

Hello. I have an app that runs the real browser, connects to it via webSocket, and then produce some request. There is above the code, which is used to run the browser and connect to it. Every time the app received the request - it calls connectOverCDP and creates new pages inside. Usually, it works well, but sometimes there is an issue

/app-path/node_modules/playwright-core/lib/client/frame.js:57
    return frame._object;
                 ^

TypeError: Cannot read property '_object' of undefined
    at Function.from (/home/sergey/Work/ticketing/booking/node_modules/playwright-core/lib/client/frame.js:57:18)
    at Proxy.<anonymous> (/home/sergey/Work/ticketing/booking/node_modules/playwright-core/lib/client/page.js:162:46)
    at Proxy.emit (events.js:400:28)
    at Connection.dispatch (/home/sergey/Work/ticketing/booking/node_modules/playwright-core/lib/client/connection.js:190:21)
    at Immediate.<anonymous> (/home/sergey/Work/ticketing/booking/node_modules/playwright-core/lib/inprocess.js:44:83)

It appears randomly and seems like a bug.

dgozman commented 3 years ago

@kt-vv If you could run with DEBUG=pw:protocol,pw:channel* and post the logs here, that would help us with debugging the issue. Alternatively, a repro script that we can run locally is also good.

kt-vv commented 3 years ago
  pw:protocol ◀ RECV {"method":"Page.frameDetached","params":{"frameId":"7465DE3A968D380A26AD7C51A33BA280","reason":"remove"},"sessionId":"C6367425AB3C5A7BB8E604668AA70FA9"} +0ms
  pw:protocol ◀ RECV {"method":"Page.lifecycleEvent","params":{"frameId":"5BDDBA8C45FFFA7FC46880148955DF34","loaderId":"3ED27EE1F2083CCBCE778A0256DFF2D8","name":"init","timestamp":176664.948112},"sessionId":"C6367425AB3C5A7BB8E604668AA70FA9"} +1ms
  pw:protocol ◀ RECV {"method":"Page.frameDetached","params":{"frameId":"0C1A709AA6A871AC293B76344C5A73F3","reason":"remove"},"sessionId":"1496D80D09D0278066D937833CD644EC"} +0ms
  pw:protocol ◀ RECV {"method":"Network.requestWillBeSent","params":{"requestId":"366530.232","loaderId":"B0738343E514AC89461E699F5471E7C4","documentURL":"https://www.delta.com/flight-search/book-a-flight","request":{"url":"https://p11.techlab-cdn.com/collect?t=1635582046234&st=91680&s=bt6bxr92ns1F5Wem&ss=3&c=5eb98f27f913a30d77a1d98e&r=wSqwQGEXKU0EpQGD&d=0&u=https%3A%2F%2Fwww.delta.com%2Fflight-search%2Fbook-a-flight&v=747623350&p=1&bv=9&rh=2257bdd1bff0949c9e9ad67f9e257c29&pi=6787&pl=13040&pwl=13052&ple=13043&psd=668&ppu=0&psl=90&pfu=1152&phe=16&pue=14&pbc=13&pnu=-1&pnc=-1&pnr=-1&fsp=0&sp=0&ah=0&sm=1&tr=1","method":"POST","headers":{"sec-ch-ua":"\"Chromium\";v=\"94\", \"Google Chrome\";v=\"94\", \";Not A Brand\";v=\"99\"","Referer":"https://www.delta.com/","Accept-Language":"en-US","sec-ch-ua-mobile":"?0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36","sec-ch-ua-platform":"\"Linux\"","Content-Type":"text/plain"},"hasPostData":true,"mixedContentType":"none","initialPriority":"VeryLow","referrerPolicy":"strict-origin-when-cross-origin","isSameSite":false},"timestamp":176664.940748,"wallTime":1635582046.248065,"initiator":{"type":"script","stack":{"callFrames":[{"functionName":"vg.k","scriptId":"7","url":"https://url06c69f9a6063120c0d0265eb98f27f913a30d77a1d98e","lineNumber":91,"columnNumber":401},{"functionName":"nb","scriptId":"7","url":"https://url06c69f9a6063120c0d0265eb98f27f913a30d77a1d98e","lineNumber":239,"columnNumber":170},{"functionName":"nd","scriptId":"7","url":"https://url06c69f9a6063120c0d0265eb98f27f913a30d77a1d98e","lineNumber":240,"columnNumber":26},{"functionName":"","scriptId":"7","url":"https://url06c69f9a6063120c0d0265eb98f27f913a30d77a1d98e","lineNumber":238,"columnNumber":310},{"functionName":"Sa","scriptId":"7","url":"https://url06c69f9a6063120c0d0265eb98f27f913a30d77a1d98e","lineNumber":58,"columnNumber":350},{"functionName":"mb","scriptId":"7","url":"https://url06c69f9a6063120c0d0265eb98f27f913a30d77a1d98e","lineNumber":56,"columnNumber":466}]}},"type":"Ping","frameId":"5BDDBA8C45FFFA7FC46880148955DF34","hasUserGesture":false},"sessionId":"1496D80D09D0278066D937833CD644EC"} +0ms
  pw:protocol ◀ RECV {"method":"Page.frameDetached","params":{"frameId":"7465DE3A968D380A26AD7C51A33BA280","reason":"remove"},"sessionId":"1496D80D09D0278066D937833CD644EC"} +0ms
  pw:protocol ◀ RECV {"method":"Page.lifecycleEvent","params":{"frameId":"5BDDBA8C45FFFA7FC46880148955DF34","loaderId":"3ED27EE1F2083CCBCE778A0256DFF2D8","name":"init","timestamp":176664.948112},"sessionId":"1496D80D09D0278066D937833CD644EC"} +0ms
  pw:channel:event {
  pw:channel:event   guid: 'page@4a16bd341224e2136b4fd57d47d6bd18',
  pw:channel:event   method: 'frameDetached',
  pw:channel:event   params: { frame: { guid: 'frame@3d03b3159b30fb379d94779fca9a2405' } }
  pw:channel:event } +1ms
  pw:channel:event {
  pw:channel:event   guid: 'page@4a16bd341224e2136b4fd57d47d6bd18',
  pw:channel:event   method: 'frameDetached',
  pw:channel:event   params: { frame: { guid: 'frame@0451b2ab1f56487acfd8c5c321632411' } }
  pw:channel:event } +0ms
  pw:channel:event {
  pw:channel:event   guid: 'page@102911bd7e02c0f72dd9d2cb1d8acc01',
  pw:channel:event   method: 'frameDetached',
  pw:channel:event   params: { frame: undefined }
  pw:channel:event } +0ms
/home/sergey/Work/ticketing/booking/node_modules/playwright-core/lib/client/frame.js:57
    return frame._object;
                 ^

TypeError: Cannot read property '_object' of undefined
    at Function.from (/home/sergey/Work/ticketing/booking/node_modules/playwright-core/lib/client/frame.js:57:18)
    at Proxy.<anonymous> (/home/sergey/Work/ticketing/booking/node_modules/playwright-core/lib/client/page.js:162:46)
    at Proxy.emit (events.js:400:28)
    at Connection.dispatch (/home/sergey/Work/ticketing/booking/node_modules/playwright-core/lib/client/connection.js:190:21)
    at Immediate.<anonymous> (/home/sergey/Work/ticketing/booking/node_modules/playwright-core/lib/inprocess.js:44:83)

console output The app is too big, so I can't copy the whole code, but the repro script will be like:

let browser = await chromium.connectOverCDP({wsEndpoint: wsRealEndpoint, timeout: 20000});
let contextOptiopns = {
      ignoreHTTPSErrors: true,
      locale: 'en-US',
      ...contextOptions
    }
let context = await browser.newContext(contextOptiopns);
let page = await context.newPage();

Every request calls this code and initializes a new instance via connectOverCDP, then fills different forms and gets parsers results. After randomly numbers of requests to the app, it fails with the above error

kt-vv commented 3 years ago

Have the same issue on Playwright Version: 1.16.2

mxschmitt commented 3 years ago

Which Google Chrome version are you using and does normal launch not work for you?

Also we need a full repro, preferable inside a small Docker container.

kt-vv commented 3 years ago

sorry, it seems it was my mistake with the version. After upgrading to the last version can not reproduce