browserless 1.0.0 copy "browserless: ^1.0.0" to clipboard
browserless: ^1.0.0 copied to clipboard

A fully-typed Dart SDK for interacting with Browserless via REST and WebSockets.

example/browserless_example.dart

import 'package:browserless/browserless.dart';
import 'package:dotenv/dotenv.dart';

void main() async {
  var env = DotEnv(includePlatformEnvironment: true)..load();

  String? endpoint = env['BROWSERLESS_ENDPOINT'];
  String? token = env['BROWSERLESS_TOKEN'];

  if (endpoint == null || token == null) {
    print(
      'Please provide BROWSERLESS_ENDPOINT and BROWSERLESS_TOKEN via a .env file or system environment variables.',
    );
    return;
  }

  // Initialize the HTTP API
  final httpApi = BrowserlessHttpApi(baseUrl: endpoint, defaultToken: token);

  // Initialize the WebSocket API
  final wsApi = BrowserlessWebSocketApi(baseUrl: endpoint, defaultToken: token);

  // Example HTTP request: fetch active sessions
  try {
    final sessions = await httpApi.json.list();
    print('Active sessions count: ${sessions.length}');
  } catch (e) {
    print('Failed to get active sessions: $e');
  }

  // Example WebSocket connection
  try {
    final ws = wsApi.chromium();
    print('WebSocket connecting...');
    await ws.ready;
    print('WebSocket connected successfully!');
    await ws.sink.close();
  } catch (e) {
    print('WebSocket connection failed: $e');
  }
}
0
likes
160
points
27
downloads

Documentation

API reference

Publisher

verified publishermrcrbrth.my.id

Weekly Downloads

A fully-typed Dart SDK for interacting with Browserless via REST and WebSockets.

Repository (GitHub)

License

MIT (license)

Dependencies

http, web_socket_channel

More

Packages that depend on browserless