awake-maroonA
Apify & Crawlee3y ago
1 reply
awake-maroon

How can I open a new browser tab from within a router handler?

Hi there,

I'm currently running a PlaywrightCrawler with crawlee and I would like to open a new tab from within a route handler, so that I can run the following:
router.addHandler('*/ergebnisse.xhtml', async ({ request, page, log, session }) => {
  // create a new tab & start navigating it concurrently
  const browserContext = await page.browserContext();
  const newTab = await browserContext.newTab.goTo("*/documents-dk.xhtml");
  const [_, data] = await Promise.all([
    // 1. initiate navigation on the new tab
    navigateThroughPage(newTab);
    // 2. Now, do stuff on current `page`
    downloadSomething(page);
  ])
  // finally, do some stuff on the new Tab
  const data2 = await downloadSomething(newTab);
})


Would that actually work?

NB: The website supports only downloading one single request at a time via cookies. Since the navigation on the new tab takes some time though, I'd like to run that concurrently in two tabs while the first request downloads.

Then, after that's done, i'd like to initiate the second download on the already pre-navigated page.

LMK if the context here is not clear.
Was this page helpful?