简体   繁体   中英

Launch Puppeteer on a manual Page

Is it possible to manually navigate to a Page, then launch a Puppeteer Script there, navigate to a different Page, launch script there, and so on..

I already did a bit of research but couldn't find anything.

I need to autofill a Calendar but its a little bit difficult to automate the whole Process, so it would be nice if I could navigate manually and launch the script when needed

Does anyone know if this is possible??

You could code an interactive console app, Like the one explained here . On that app, you would launch a browser with headless in false, navigate where you want to go, and then from the console app you could type a command like fillform and execute the puppeteer code you want to run.

Not sure why someone down voted?

Yeah it's possible. It's not recommended. It's better to work your way through the errors and then understand how page automation really works. This is the point of Puppeteer. It's also already possible to run JavaScript on a page in chrome, using the console in dev-tools.

But if you wanted to manually navigate to a page using puppeteer, then run 'macros' on the page using node.js based on a condition, you'd want to do something like this:

  1. headless: false launch (obviously so you can see the browser)

  2. have your script/fill in function wait for an event on the page like a request which indicates the page was refreshed. You might be able to use page.on() event to trigger the code wait for the request to finish.

     await page.setRequestInterception(true); page.on('request', request => { // Override headers const headers = Object.assign({}, request.headers(), { foo: 'bar', // set "foo" header origin: undefined, // remove "origin" header }); request.continue({headers}); });

from puppeteer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM