Skip to content

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

Closed

Description

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?

Activity

  1. JoelEinbinder commented on Mar 24, 2021

    @JoelEinbinder
    Contributor

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

  2. trueadm commented on Mar 24, 2021

    @trueadm
    Author

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

  3. trueadm commented on Mar 24, 2021

    @trueadm
    Author

    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
  4. trueadm commented on Mar 24, 2021

    @trueadm
    Author

    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.

  5. JoelEinbinder commented on Mar 24, 2021

    @JoelEinbinder
    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.

  6. trueadm commented on Mar 24, 2021

    @trueadm
    Author
  7. trueadm commented on Mar 24, 2021

    @trueadm
    Author

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

  8. JoelEinbinder commented on Mar 24, 2021

    @JoelEinbinder
    Contributor
  9. trueadm commented on Mar 24, 2021

    @trueadm
    Author

    Joel Einbinder (@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. :/

  10. added a commit that references this issue on Apr 2, 2021
    63e16b4
  11. added a commit that references this issue on Apr 2, 2021
    4da2d6e
  12. JoelEinbinder commented on Apr 5, 2021

    @JoelEinbinder
    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

Metadata

Metadata

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