Skip to content

[BUG] intercepts pointer events, unable to click in chromium #19898

Closed

Description

Context:

  • Playwright Version: ^1.29.1
  • Operating System: Windows11
  • Node.js Version: v19.0.1
  • Browser: Chromium

Code Snippet

test("repro", async ({ page, context }) => {
  await page.goto('http://localhost:8080');
  await page.locator('#theForceIsStrongWithThisOne').click({ timeout: 3000 });
});

HTML:

<body id="divID">
  <div id="container" class="container somethingPage" style="height: auto;">
    <div class="banner" id="pageBanner">
      <div id="bannerImageContainer" class="bannerImageLeftAlign" style="background: rgb(255, 255, 255);">
        <img id="headerImage" src="./files/large-company-logo.png">
      </div>
    </div>
    <main class="somethingInfo">
      <div class="documentTitle" id="documentTitle">
        <div class="filterIconContainer">
          <span id="theForceIsStrongWithThisOne" class="filter"></span> <!-- This is the target -->
        </div>
        <p id="somethingHeader" class=""><b class="heading">Keep On Darthin' In The Free World</b></p>
      </div>
      <div id="readOnlyWarning">
        <p><b>These are the blog articles you are looking for, if not, use the filter button above.</b></p>
      </div>
    </main>
  </div>
</body>

I also note that there is CSS for the "filter" class:

.filter:after {
    position: absolute;
    border-left: .25em solid;
    left: -.125em;
    top: -.2em;
    height: .4em;
    content: ' '
}

Describe the bug

When running this (only) in Chromium, as you will see in the trace below, while playwright correctly highlights the filter control, it is going to perform the click elsewhere and so the error that is returned makes sense "</body> intercepts pointer events"
image
I have a feeling this is probably not playwright and more likely chromium itself but this is somewhat further than I know to go in the code to really get to the bottom of it.

Click here for the log produced:
waiting for locator('#theForceIsStrongWithThisOne')
locator resolved to visible <span class="filter" id="theForceIsStrongWithThisOne"></span>
attempting click action
waiting for element to be visible, enabled and stable
element is visible, enabled and stable
scrolling into view if needed
done scrolling
<body id="divID">…</body> intercepts pointer events
retrying click action, attempt #1
waiting for element to be visible, enabled and stable
element is visible, enabled and stable
scrolling into view if needed
done scrolling
<body id="divID">…</body> intercepts pointer events
retrying click action, attempt #2
waiting 20ms
waiting for element to be visible, enabled and stable
element is visible, enabled and stable
scrolling into view if needed
done scrolling
<body id="divID">…</body> intercepts pointer events
retrying click action, attempt #3
waiting 100ms
waiting for element to be visible, enabled and stable
element is visible, enabled and stable
scrolling into view if needed
done scrolling
<body id="divID">…</body> intercepts pointer events
retrying click action, attempt #4
waiting 100ms
waiting for element to be visible, enabled and stable
element is visible, enabled and stable
scrolling into view if needed
done scrolling
<body id="divID">…</body> intercepts pointer events
retrying click action, attempt #5
waiting 500ms
waiting for element to be visible, enabled and stable
element is visible, enabled and stable
scrolling into view if needed
done scrolling
<body id="divID">…</body> intercepts pointer events
retrying click action, attempt #6
waiting 500ms
waiting for element to be visible, enabled and stable
element is visible, enabled and stable
scrolling into view if needed
done scrolling
<body id="divID">…</body> intercepts pointer events
retrying click action, attempt #7
waiting 500ms
waiting for element to be visible, enabled and stable
element is visible, enabled and stable
scrolling into view if needed
done scrolling
<body id="divID">…</body> intercepts pointer events
retrying click action, attempt #8
waiting 500ms
waiting for element to be visible, enabled and stable
element is visible, enabled and stable
scrolling into view if needed
done scrolling
<body id="divID">…</body> intercepts pointer events
retrying click action, attempt #9
waiting 500ms

Here is the output from the console:

  3 | test("repro", async ({ page, context }) => {
  4 |   await page.goto("http://localhost:8080");
> 5 |   await page.locator("#theForceIsStrongWithThisOne").click({ timeout: 3000 });
    |                                                      ^
  6 | });

  at c:\Users\DannyCrone\repos\click-repro\tests\repro.spec.ts:5:54

click-repro.zip

This project contains a repro website to test against and 1 test

  • website is in the folder "website"
  • test is called "repro" in "repro.spec.ts"

In order to run the website so it renders the page correctly, I used http-server using the following command:

http-server website -c-1

Also included it as an npm script:

  "scripts": {
    "start": "http-server website -c-1"
  },

Attached are the traces from chromium (failing) and webkit (passing):
chromiumtrace.zip
webkittrace.zip

Activity

  1. gauravgandhi1315 commented on Jan 5, 2023

    @gauravgandhi1315

    Danny Crone (@dannycrone) I tried your website and the code below works for me. Instead of click use this:

    async clickOnElement(selector) {
        await page.evaluate((selector) => {
          return document.querySelector(selector).click();
        }, selector);
      }
    

    I used selector #theForceIsStrongWithThisOne

  2. dannycrone commented on Jan 5, 2023

    @dannycrone
    Author

    GG (@gauravgandhi1315), thanks for that, we already have workarounds which are:

    test("repro1", async ({ page }) => {
      await page.goto("http://localhost:8080");
      await page.locator("#theForceIsStrongWithThisOne").dispatchEvent('click');
    });
    
    test("repro2", async ({ page }) => {
      await page.goto("http://localhost:8080");
      page.locator("#theForceIsStrongWithThisOne").evaluate((el) => {
        (el as HTMLElement).click();
      });
    });

    But neither of these nor yours actually perform the mouse click which is what we would prefer (if that makes sense?).

  3. gauravgandhi1315 commented on Jan 5, 2023

    @gauravgandhi1315

    Danny Crone (@dannycrone) ok, but it worked for me in my local.

  4. mxschmitt commented on Jan 5, 2023

    @mxschmitt
    Contributor

    I was able to create a minimal repro out of it:

    image

    import playwright from 'playwright';
    const browser = await playwright.chromium.launch({
      headless: false,
    });
    const context = await browser.newContext();
    const page = await context.newPage();
    
    await page.goto('about:Blank');
    await page.setContent(`
    <style>
        .some-wrapper {
            padding-left: 25px;
            zoom: 2;
        }
    </style>
    
    <body>
        <div class="some-wrapper">
            <button>test</button>
        </div>
    </body>
    `);
    await page.getByText('test').click();
    await browser.close();
  5. mxschmitt commented on Jan 5, 2023

    @mxschmitt
    Contributor

    Turns out this is a duplicate of #7642, folding into it.

    For now we recommend await page.locator("#foobar").evaluate(element => element.click());

  6. dannycrone commented on Jan 6, 2023

    @dannycrone
    Author

    Max Schmitt (@mxschmitt), great detective work! and while #7642 is closed and not fixed, it leads me to have a conversation with the dev team about replacing zoom with transform, so thank you :)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions