Reputation: 91
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??
Upvotes: 2
Views: 857
Reputation: 21695
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.
Upvotes: 3
Reputation: 484
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:
headless: false launch (obviously so you can see the browser)
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});
});
Upvotes: 1