xvrh / puppeteer-dart

A Dart library to automate the Chrome browser over the DevTools Protocol. This is a port of the Puppeteer API
BSD 3-Clause "New" or "Revised" License
236 stars 59 forks source link

Unhandled exception: Context is disposed #237

Open plztrial4me opened 1 year ago

plztrial4me commented 1 year ago

I'm using puppeteer version 3.0.0.

In the source code below, a exception is thrown only when the "siteUrl" value is https://www.naver.com. However, it does not occur when the "siteUrl" value is https://www.google.com.

I haven't found what is causing the exception to be thrown. I need help.

The result of running the source code is shown below.

2023-05-30 16:24:00.005092: refresh() 2023-05-30 16:25:00.001224: refresh() 2023-05-30 16:26:00.002222: refresh() 2023-05-30 16:27:00.001646: refresh() 2023-05-30 16:28:00.001427: refresh() 2023-05-30 16:29:00.001050: refresh() 2023-05-30 16:30:00.001667: refresh() 2023-05-30 16:31:00.001120: refresh() 2023-05-30 16:32:00.002009: refresh() 2023-05-30 16:33:00.001106: refresh() Unhandled exception: Context is disposed

import "package:cron/cron.dart";
import "package:puppeteer/puppeteer.dart";

void main(List<String> arguments) async {
  const siteUrl = "https://www.naver.com";
  late final Browser browser;

  try {
    browser = await puppeteer.launch(
      headless: false,
      defaultViewport: null,
      args: [
        '-window-size=1920,1080',
        '--disable-web-security',
        '--disable-features=IsolateOrigins,site-per-process',
      ],
    );

    final cron = Cron();
    cron.schedule(Schedule.parse('*/1 * * * *'), () async {
      // Open a new tab to access the site and close it
      try {
        print('${DateTime.now().toString()}: refresh()');
        final page = await browser.newPage();
        await page.goto(siteUrl, wait: Until.networkIdle);
        await page.close();
      } catch (e, stack) {
        print('schedule exception');
        print(e);
        print(stack);
      }
    });

    final page = await browser.newPage();
    await page.goto(siteUrl);
  } catch (e, stack) {
    print('main exception');
    print(e);
    print(stack);
  }
}