dart-lang / html

Dart port of html5lib. For parsing HTML/HTML5 with Dart. Works in the client and on the server.
https://pub.dev/packages/html
Other
276 stars 58 forks source link

BrowserClient sometimes throws [object ProgressEvent] error. #207

Closed dzziwny closed 1 year ago

dzziwny commented 1 year ago

In the example code of flutter app, there is a working and not working url.

import 'dart:html';

import 'package:flutter/material.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: FutureBuilder<String>(
        future: statusCode(),
        builder: (context, snapshot) => Text((snapshot.data ?? '')),
      ),
    );
  }

  Future<String> statusCode() async {
    try {
      final workingUrl = 'http://ip-api.com/json';
      final notWorkingUrl = 'https://mock.codes/200';

      final response = await HttpRequest.request(notWorkingUrl);
      return response.status.toString();
    } catch (error) {
      return '$error';
    }
  }
}

In working case, app prints 200, In not working case [object ProgressEvent] with parameter inside: <error>: <getObject: Unexpected error from chrome devtools:>

Here is also a dartpad example with similar problem - https://dartpad.dev/?id=fb517ae8faa4e1dacd59e627e231bd83.

This is a minimalistic example, in a production app we have a problem with all responses that has no successful status code.

devoncarew commented 1 year ago

I believe this issue may have been mis-filed? This is a package used to parse html source into a DOM - https://github.com/dart-lang/html#usage.

dzziwny commented 1 year ago

There's nothing around parsing html. In the example, there is a HTTP call, that should return 200, but fails without a clear reason. Is the example work for you @devoncarew? If you call both urls from postman or browser, you'll get 200. Why from dart one of them fails?