Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Control+Shift+ArrowLeft fails on contenteditables with FF + Linux #5929

Closed
trueadm opened this issue Mar 23, 2021 · 10 comments · Fixed by #6052
Closed

[BUG] Control+Shift+ArrowLeft fails on contenteditables with FF + Linux #5929

trueadm opened this issue Mar 23, 2021 · 10 comments · Fixed by #6052
Assignees

Comments

@trueadm
Copy link

trueadm commented Mar 23, 2021

Context:

  • Playwright Version: 1.9.2
  • Operating System: Linux
  • Node.js version: 12
  • Browser: Firefox

Code Snippet

const {chromium, webkit, firefox} = require('playwright');

(async () => {
  const browser = await chromium.launch();
  // ...
  // locate <div contenteditable="true" id="contenteditable"></div>
  await page.focus('#contenteditable');
  await page.keyboard.type('Hello world');
  await page.keyboard.down('Control');
  await page.keyboard.down('Shift');
  await page.keyboard.press('ArrowLeft');
  await page.keyboard.up('Shift');
  await page.keyboard.up('Control');
  // Expectation is that the word "world" should be selected.
})();

Describe the bug

This was a strange issue for us. We encountered it on our CI that runs Linux and after playing around, we were able to determine that this only occurs for Firefox on Linux. Specifically, it also only seems to affect contenteditable="true" nodes. It works fine for <input> elements.

It seems that this does nothing in FF for Linux. The expected behavior is to select the word "world", as the keyboard shortcut Control + Shift + ArrowLeft is intended to do (works fine natively using Linux and contenteditables with FF).

Note: when we run this test, we are also running the same test on other browsers too. Could it be that there's a foreground issue with selection and FF?

@JoelEinbinder
Copy link
Contributor

Added a test that passes for me on firefox/linux. Maybe there is something mores specific happening with your contenteditable div?

@trueadm
Copy link
Author

trueadm commented Mar 24, 2021

@JoelEinbinder Interesting. I'll dig more into it today. I suspect it's a foreground problem maybe on the CI machine.

@trueadm
Copy link
Author

trueadm commented Mar 24, 2021

I'm fairly certain something is going wrong here. I've stripped back the test case so we aren't running any JS and the page is just an empty document with a contenteditable div. I also noticed that this works locally for me using Ubuntu and FF, it just doesn't seem to work when run in a virtualized environment, like Github Actions.

This is the HTML:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
  </head>
  <body>
    <div id="contenteditable" contenteditable="true"></div>
  </body>
</html>

This is the test case:

it(`Can select and delete a word`, async () => {
  const {page} = e2e;

  await page.focus('#contenteditable');
  await page.keyboard.type('Hello world');
  await page.keyboard.down('Control');
  await page.keyboard.down('Shift');
  await page.keyboard.press('ArrowLeft');
  await page.keyboard.up('Shift');
  await page.keyboard.up('Control');
  // Log screenshot

  await page.keyboard.press('Backspace');
  const remainingText = await page.textContent(
    '#contenteditable',
  );
  expect(remainingText).toBe('Hello ');
});

The screenshot just before backspace in Linux + FF on CI:

cbimage

Here's out Github Actions config:

name: Tests
on: [push]
jobs:
  e2e:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [12.x]
    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: yarn install
    - run: yarn build
    - run: yarn test
      env:
        CI: true

@trueadm
Copy link
Author

trueadm commented Mar 24, 2021

Interestingly, if I change the test case to be:

await page.focus('#contenteditable');
await page.keyboard.type('Hello world');
await page.keyboard.down('Shift');
await page.keyboard.press('ArrowLeft');
await page.keyboard.press('ArrowLeft');
await page.keyboard.press('ArrowLeft');
await page.keyboard.press('ArrowLeft');
await page.keyboard.press('ArrowLeft');
await page.keyboard.up('Shift');

It works fine on FF+Linux on CI. So it does seem like a bug with Playwright.

@JoelEinbinder
Copy link
Contributor

I can repro it on 1.9.2 but not on tip of tree. Looks like it was fixed via the latest firefox roll. v1.10 should be coming shortly with the fix. Or you can install npm install playwright@next if you are impatient.

@trueadm
Copy link
Author

trueadm commented Mar 24, 2021

@JoelEinbinder Awesome! Thanks :)

@trueadm
Copy link
Author

trueadm commented Mar 24, 2021

This is so strange. With playwright@next, FF now passes for Linux on CI but fails when run locally on my Mac.

@JoelEinbinder
Copy link
Contributor

JoelEinbinder commented Mar 24, 2021 via email

@trueadm
Copy link
Author

trueadm commented Mar 24, 2021

@JoelEinbinder Yep, we use a function that detects platform and uses the right key. What's strange is that if I run in head mode and insert a debugger in the keydown listener on ArrowLeft, the selection then gets applied. Seems like there's maybe a timing or sequencing issue at play? If I switch back to 1.9.2, the same test passes on my Mac locally but fails on CI. :/

@JoelEinbinder
Copy link
Contributor

Fixed via #6052 verified via #6034

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants