-
Notifications
You must be signed in to change notification settings - Fork 9k
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
page.keyboard.*
: pressing Ctrl-F doesn't act as pressing it manually
#2210
Comments
It turns out that window.find() is implemented in Chrome. So the following code emulates the Ctrl-F mechanism (except the color of highlights and perhaps some other things): /* global window */
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.evaluate(() => window.find('example')); // to the first match
await page.evaluate(() => window.find('example')); // to the second match
await page.screenshot({ path: 'example.png' });
console.log('Made a screenshot'); // the second match is highlighted
})(); Anyway, it would be interesting to hear on the
|
@JoelEinbinder can you please take a look? Sounds similar to Ctrl-A case. |
I got confused. The Ctrl-F you try to emulate is a chromium shortcut; pptr doesn't dispatch input events to chromium - only to the webpage. So this kind of functionality is not possible with pptr. |
@aslushnikov, I'm trying to simulate
I'm trying to trigger command 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 Is there a solution to my problem? Or is it the same limitation of Puppeteer as you described to OP? |
@dvdvdmt hi, Has your problem been solved? I have the same problem as you. |
@BlackHole1 hello, yes I've managed it by writing additional code that listens for keyboard shortcuts on page level (content script) and sends it back to background script. You can see my code in this issue dvdvdmt/popup-tab-switcher#1 |
My plugin requires activeTab permissions. One of the ways to open this permission is to use shortcut keys. So I want to use the puppeterer input shortcut to open the activeTab permission. |
However, this method does not work. But thank you very much for your answer. |
@BlackHole1 any luck so far? I have the same problem with activeTab permissions. |
--whitelisted-extension-id= does the work for me |
@bmoers Wow, brother, you are so great. Thank you very much. According to your answer, I looked at the Chrome source and found this to be feasible! |
@BlackHole1 After add the whitelisted-extension-id ,I can‘t use the puppeterer input shortcut to open the activeTab permission.Is there anything to watch out for? |
@298068845 You don't need to use a shortcut, just call this function directly. |
@BlackHole1 https://github.com/s16h/puppeteer-tab-capture-repro/blob/master/test.js |
@298068845 Maybe you can try my open source project: https://github.com/alo7/rebirth open Chrome Code: https://github.com/alo7/rebirth/blob/master/src/lib/startChrome.js#L7-L27 start capture Code: https://github.com/alo7/rebirth/blob/master/src/chrome-extension/lib/recording.ts#L24-L76 |
Try do not use await. async function keyPress(page, char) { keyPress(page, 'Control'); |
Chrome has deprecated --whitelisted-extension-id a couple years ago, --allowlisted-extension-id={id} should be used now |
Steps to reproduce
Tell us about your environment:
What steps will reproduce the problem?
I run this code:
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:
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.
The text was updated successfully, but these errors were encountered: