Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppressing asynchronous exceptions to avoid app crashes #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

caybear
Copy link

@caybear caybear commented Nov 7, 2019

App crash stackTrace:

Unhandled exception:
No resource with given identifier found
#0      NetworkApi.getResponseBody (package:puppeteer/protocol/network.dart:299:18)
<asynchronous suspension>
#1      Response.content.<anonymous closure> (package:puppeteer/src/page/network_manager.dart:573:12)
<asynchronous suspension>
#2      _RootZone.runUnary (dart:async/zone.dart:1379:54)
#3      _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#4      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#5      Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#6      Future._completeWithValue (dart:async/future_impl.dart:522:5)
#7      Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:552:7)
#8      _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#9      _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#10     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:116:13)
#11     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:173:5)

Suppressing asynchronous exceptions to avoid app crashes
@xvrh
Copy link
Owner

xvrh commented Nov 7, 2019

Hello @caybear,
Thanks for the contribution :-)

Can give an example when this crash happens? (ideally a small reproduction script)

@caybear
Copy link
Author

caybear commented Nov 7, 2019

@xvrh This code will crash the app.
Execute this command "chrome.exe --remote-debugging-port=9222" before execute following code please.

import 'dart:convert';
import 'dart:io';

import 'package:puppeteer/puppeteer.dart';

final httpClient = HttpClient();

main(List<String> arguments) async {
  /**
   * Get browser endpoint.
   *
   * clientInfo['webSocketDebuggerUrl'].
   */
  String endpoint;
  try {
    final HttpClientRequest request =
        await httpClient.getUrl(Uri.parse('http://127.0.0.1:9222/json/version'));
    final HttpClientResponse response = await request.close();
    final Map<String, dynamic> clientInfo = jsonDecode(await utf8.decoder.bind(response).join(''));
    endpoint = clientInfo['webSocketDebuggerUrl'];
  } on Exception catch (message) {
    print(message);
    return;
  }

  final browser = await puppeteer.connect(browserWsEndpoint: endpoint);
  final webPage = await browser.newPage();
  webPage.onResponse.listen((response) async {
    if (response.url.contains('xiaohei.jpg')) print((await response.content).length);
  });

  await webPage.goto('https://produce.unimap.ai:12080/dart.html', wait: Until.domContentLoaded);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants