Skip to content

[BUG]: Mock issue on Playwright 1.49+ using MPTS #162

Description

@hcura-qa

Describe the bug
After the Playwright update to version 1.49.0 (also tested with 1.49.1), the native Playwright mocking tool (route()) is not working anymore when running using Microsoft Playwright Testing service (MPTS).

The test using a mocked call is failing with the following error:

Error: Socks5 proxy rejected connection - ConnectionRefused
Call log:
  - → POST <undisclosed>
    - user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.6778.33 Safari/537.36
    - accept: application/json, text/plain, */*
    - accept-encoding: gzip,deflate,br
    - accept-language: en-US
    - content-type: application/json
    - cookie: <undisclosed>
    - origin: <undisclosed>
    - referer: <undisclosed>
    - sec-ch-ua: "HeadlessChrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"
    - sec-ch-ua-mobile: ?0
    - sec-ch-ua-platform: "Windows"
    - content-length: 93

We suspect the issue might be caused with the recent architecture change related to Chromium headless, that can be found here: microsoft/playwright#33566

To Reproduce
Steps to reproduce the behavior:

  1. Run a test with a mocked call (using route() Playwright's native method)
  2. Perform a route.fetch() - reproducible with our app so far
  3. Observe

Screenshots
N/A

Setup information (please complete the following information):

  • Session Id: 82601638-f67d-4a8c-95bb-dc2db38b6a2d
  • Browser on which tests are executed: Chromium
  • Playwright Version: 1.49+
  • Client machine OS: Linux
  • OS requested on Service: Linux

Additional context
The affected test has no issues when running against our Github runners infrastructure. This is a 100% reproducible issue using Microsoft Playwright Testing Service.

Activity

  1. changed the title [-][BUG]: Mock is not supported on Playwright 1.49+ using PTS[/-] [+][BUG]: Mock is not supported on Playwright 1.49+ using MPTS[/+] on Dec 23, 2024
  2. manikanta-addagatla commented on Dec 27, 2024

    @manikanta-addagatla

    Hi,
    We couldn't reproduce this issue from our end. Tried with simple test using route() and test has passed.

    Could you please provide a sample to repro the issue?

  3. hcura-qa commented on Dec 30, 2024

    @hcura-qa
    Author

    I've implemented a test with similar steps, but the issue is not happening here (sessionId 074d7a6b-906e-4d85-b5f1-5f7109290f31):

      test('generic mock test', async ({ page }) => {
        const searchString = 'hcura-qa';
        const mockedName = 'Mocked Name';
    
        await page.goto('https://gh-users-search.netlify.app/');
        await page.route(`*/**/users/${searchString}`, async (route) => {
          const response = await route.fetch();
          let body = await response.json();
    
          body.name = mockedName;
    
          await route.fulfill({
            status: 200,
            body: JSON.stringify(body),
          });
        });
    
        await page.getByTestId('search-bar').fill(searchString);
        await page.getByRole('button', { name: 'search' }).click();
        await expect(page.getByRole('heading', { name: mockedName, level: 4 })).toBeVisible();
      });
    

    For us, when running our app using MPT service under CI, the referred failure is happening on line "const response = await route.fetch();".

    It is not happening when using our infrastructure (github runners), and it happens when running over MPT service, with Playwright 1.49+, and it is not reproducible locally, that's why we think the issue is likely related to MPT.

  4. changed the title [-][BUG]: Mock is not supported on Playwright 1.49+ using MPTS[/-] [+][BUG]: Mock issue on Playwright 1.49+ using MPTS[/+] on Dec 30, 2024
  5. Sid200026 commented on Jan 7, 2025

    @Sid200026
    Member

    Hi Hugo Cura (@hcura-qa), from the initial error message shared, I see that the User-Agent indicates Windows operating system while you had mentioned that the client OS is Linux. I'm assuming you are running tests using some proxy server which is running on Windows.

    - user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.6778.33 Safari/537.36
    - sec-ch-ua-platform: "Windows"
    

    Could you provide us with the below details which would help us investigate the issue further

    • The previous version in which your test was working with Microsoft Playwright Testing Service
    • Node version
    • Playwright configuration file
    • If you are using some http proxy or socksv5 in your tests
    • Client-side channel logs (Channel logs might contain some secrets like url, auth tokens, etc. Feel free to remove them before sending the logs)
  6. puagarwa commented on Jan 17, 2025

    @puagarwa
    Member

    HI Hugo Cura (@hcura-qa) , Gentle reminder if you got chance to look into above info.

  7. miguelofbc commented on Jan 23, 2025

    @miguelofbc

    Puneet Agarwal (@puagarwa) Siddharth Singha Roy (@Sid200026) We’ve successfully replicated the failure, but it’s now blocking an important initiative. Hugo Cura (@hcura-qa) has already reached out to the suggested contact via email. Could you please take a look at this as soon as possible? If the logs we’re sharing aren’t sufficient to identify the issue, feel free to schedule time tomorrow for further debugging.

  8. miguelofbc commented on Jan 24, 2025

    @miguelofbc

    Hello Puneet Agarwal (@puagarwa) Siddharth Singha Roy (@Sid200026),

    This issue appears to be a regression in Playwright 1.49.1. It works as expected in version 1.48.2 but fails in both 1.49.1 and 1.50.0.

    Could you please share an ETA for the fix?

    Sent some more details on email thread, but here it is the stack trace for the failure if it helps to get this issue fixed.

    Failing Logs (Playwright 1.49.1):

    pw:socks [1adac760240d34ad3b591e21a9882973] <= connect error ECONNREFUSED
    pw:channel <EVENT {"guid":"jsonPipe@46fd59359b8b3d476e774013ee0ebc12","method":"message","params":{"message":{"id":9,"error":{"error":{"message":"Socks5 proxy rejected connection - ConnectionRefused","stack":"Error: Socks5 proxy rejected connection - ConnectionRefused\n    at t.closeSocket (/usr/src/app/Workers/BrowserPodWorker/mpt-playwright-server-1_49/node_modules/playwright-core/lib/utilsBundleImpl/index.js:35:72542)\n    at t.handleSocks5FinalHandshakeResponse (/usr/src/app/Workers/BrowserPodWorker/mpt-playwright-server-1_49/node_modules/playwright-core/lib/utilsBundleImpl/index.js:35:78259)\n    at t.processData (/usr/src/app/Workers/BrowserPodWorker/mpt-playwright-server-1_49/node_modules/playwright-core/lib/utilsBundleImpl/index.js:35:71735)\n    at t.onDataReceivedHandler (/usr/src/app/Workers/BrowserPodWorker/mpt-playwright-server-1_49/node_modules/playwright-core/lib/utilsBundleImpl/index.js:35:71205)\n    at Socket.onDataReceived (/usr/src/app/Workers/BrowserPodWorker/mpt-playwright-server-1_49/node_modules/playwright-core/lib/utilsBundleImpl/index.js:35:69600)\n    at Socket.emit (node:events:514:28)\n    at addChunk (node:internal/streams/readable:324:12)\n    at readableAddChunk (node:internal/streams/readable:297:9)\n    at Readable.push (node:internal/streams/readable:234:10)\n    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)","name":"Error"}},"log":["  - → POST http://localhost:4000/rpc","    - user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.6778.33 Safari/537.36","    - accept: */*","    - accept-encoding: gzip,deflate,br","    - Content-Type: application/json","    - content-length: 136","    - cookie: session=TOKEN"]}}}
    pw:channel <RECV {"id":9,"error":{"error":{"message":"Socks5 proxy rejected connection - ConnectionRefused","stack":"Error: Socks5 proxy rejected connection - ConnectionRefused\n    at t.closeSocket (/usr/src/app/Workers/BrowserPodWorker/mpt-playwright-server-1_49/node_modules/playwright-core/lib/utilsBundleImpl/index.js:35:72542)\n    at t.handleSocks5FinalHandshakeResponse (/usr/src/app/Workers/BrowserPodWorker/mpt-playwright-server-1_49/node_modules/playwright-core/lib/utilsBundleImpl/index.js:35:78259)\n    at t.processData (/usr/src/app/Workers/BrowserPodWorker/mpt-playwright-server-1_49/node_modules/playwright-core/lib/utilsBundleImpl/index.js:35:71735)\n    at t.onDataReceivedHandler (/usr/src/app/Workers/BrowserPodWorker/mpt-playwright-server-1_49/node_modules/playwright-core/lib/utilsBundleImpl/index.js:35:71205)\n    at Socket.onDataReceived (/usr/src/app/Workers/BrowserPodWorker/mpt-playwright-server-1_49/node_modules/playwright-core/lib/utilsBundleImpl/index.js:35:69600)\n    at Socket.emit (node:events:514:28)\n    at addChunk (node:internal/streams/readable:324:12)\n    at readableAddChunk (node:internal/streams/readable:297:9)\n    at Readable.push (node:internal/streams/readable:234:10)\n    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)","name":"Error"}},"log":["  - → POST http://localhost:4000/rpc","    - user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.6778.33 Safari/537.36","    - accept: */*","    - accept-encoding: gzip,deflate,br","    - Content-Type: application/json","    - content-length: 136","    - cookie: session=TOKEN"]}
    
  9. puagarwa commented on Jan 31, 2025

    @puagarwa
    Member

    Hi Miguel Oliveira (@miguelofbc) , We have identified the fix and its already available in alpha version to try out. Fix will be ported onto 1.50 and will be available early next week.

  10. miguelofbc commented on Jan 31, 2025

    @miguelofbc

    Hello Puneet Agarwal (@puagarwa)

    Thanks for following up, that is good news! It seems to be passing now with "@playwright/test": "^1.51.0-alpha-2025-01-30". Could you please point me to the link for the PR with the fix?
    So, the plan is to release playwright 1.50.1 next week to include the fix for this, is that correct?

  11. puagarwa commented on Jan 31, 2025

    @puagarwa
    Member

    This is revert PR Revert "Reapply "fix(har timing): record connect timing for proxied connections" (#32855) (#33003)" by dgozman · Pull Request #34535 · microsoft/playwright which fixed the issue.

    That’s correct. I will update you once 1.50.1 get released and service browsers get updated with patched version.

  12. puagarwa commented on Feb 6, 2025

    @puagarwa
    Member

    Hi Miguel Oliveira (@miguelofbc) ,
    The issue is fixed in 1.50.1, please let us know if you face any issue.

  13. hcura-qa commented on Mar 19, 2025

    @hcura-qa
    Author

    This problem was fixed, no related issues so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions