question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`page.keyboard.*`: pressing Ctrl-F doesn't act as pressing it manually

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 1.2.0
  • Platform / OS version: Debian GNU/Linux 8.8 (jessie)
  • URLs (if applicable): https://example.com
  • Node.js version: 9.7.1
  • Chrome version: 65.0.3325.146 (Official Build) (64-bit)

What steps will reproduce the problem?

I run this code:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    headless: false,
    executablePath: '/usr/bin/google-chrome',
  });
  const page = await browser.newPage();
  await page.goto('https://example.com');

  await page.keyboard.down('Control');
  await page.keyboard.press('KeyF');
  await page.keyboard.up('Control');
  console.log('Pressed Ctrl-F');

  await page.keyboard.type('example');

  await page.keyboard.press('F3');
  console.log('Pressed F3');
})();

What is the expected result?

I expect that the “Find in page” widget of Chrome is opened and the word “Example” on the page is highlighted.

What happens instead?

The page just opens as if there were no page.keyboard.* calls.


The rationale is the following. I am developing an extension that changes the DOM. Sometimes it conflicts with the Ctrl-F (“Chrome menu > Find…”) mechanism:

  • The user searches something on the page and jumps to a match.
  • New elements become visible.
  • The extension changes the new visible elements (namely, text nodes with the match are detached and equivalent nodes are attached instead).
  • The match is no more highlighted.

I’d like to use puppeteer to make regression tests for this (among other things). It seems that if Ctrl-F worked, I’d get along with only puppeteer (other “meta-DOM” things work, like double-clicking and making screenshots with visible text selections and Ctrl-F highlights), but because of the issue I’ll probably have to use Xvfb and xdotool.

Is such an issue on the agenda for a future release of puppeteer? Is there some other way to use the Ctrl-F mechanism (like a JavaScript API)?

The only thing I managed to find on the issue is #2009, but that is only seemingly related.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Matos7commented, Mar 9, 2021

Try do not use await.

async function keyPress(page, char) { await page.keyboard.press(char); }

keyPress(page, ‘Control’); keyPress(page, ‘f’);

1reaction
dvdvdmtcommented, Dec 16, 2018

@aslushnikov, I’m trying to simulate Alt + Y shortcut to trigger my Chrome extension. It is listening this combination in a background script:

// manifest.json
{
  ...
  "commands": {
    "next": {
      "suggested_key": {
        "default": "Alt+Y"
      },
      "description": "Open recent tabs list. Select next"
    }
  }
}
// background.js
browser.commands.onCommand.addListener(async (command) => {
  ...
});

I’m trying to trigger command next by the following script:

const path = require('path');
const puppeteer = require('puppeteer');

(async () => {
  const pathToExtension = path.join(__dirname, '../../dist');
  const browser = await puppeteer.launch({
    headless: false,
    slowMo: 500,
    args: [
      `--disable-extensions-except=${pathToExtension}`,
      `--load-extension=${pathToExtension}`,
    ],
  });
  const [page] = await browser.pages();
  await page.goto('https://www.wikipedia.org');
  await page.keyboard.down('Alt');
  await page.keyboard.press('KeyY');
})();

When I execute this script Chromium appears, wikipedia loads, but then nothing happens. Although when I press Alt + Y manually my extension works as it should.

Is there a solution to my problem? Or is it the same limitation of Puppeteer as you described to OP?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ctrl+F does not work or bring up Find On This Page in ...
Ctrl+F does not work. Control F does not work? If when you press Ctrl+F together the Find Box does not appear, then you...
Read more >
Making Ctrl+F Work Traditionally - Word Ribbon Tips
It is possible to press Ctrl+H and then click on the Find tab, but to most people that isn't nearly as simple as...
Read more >
Keyboard shortcuts in Word - Microsoft Support
Press Ctrl+F, and then type your search words. If an action that you use often does not have a shortcut key, you can...
Read more >
Why doesn't Ctrl + F (find on page) seem to work ... - Quora
1. There is a menu bar in each program, you can use the search function through the menu bar. Shortcuts are just an...
Read more >
ctrl+f not working - Adobe Support Community - 10897623
Hi,. What is the version of Acrobat Pro that you're using? And operating system? Is this happening with every document you tyr to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found