INNER CODE UNIT · JavaScript

setupPage

sebastiancarlos/beachpatrol · beachpatrol.js:350

const setupPage = async (page) => {
  // Attach download handler
  page.on("download", handleDownload);

  // Intercept fake fetch requests from our web extension to detect page activation.
  // - The extension makes a fetch request when a page becomes active, which we intercept here
  // - This approach works cross-browser and bypasses Patchright's console/evaluate limitations,
  //   which would have been the preferred method for this feature.
  //   - Source: https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/issues/30
  await page.route('https://playwright-active-page', async (route) => {
    // This page became active, track it.
    activePage = page;

    // Fulfill the request so it doesn't fail
    await route.fulfill({ status: 200 });
  });

  // Unset activePage when a page closes.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…