Skip to content

Marionette is a library which provides a high-level API to control a WebView

License

Notifications You must be signed in to change notification settings

silverfox983/flutter_marionette

 
 

Repository files navigation

Marionette for Flutter

Marionette is a library which provides a high-level API to control a WebView.

The goal is to have the API closely mirror that of Puppeteer.

Other platforms: Swift (macOS/iOS), JavaScript (Node)

Usage

import 'package:flutter_marionette/marionette.dart';

() async {
  final page = Marionette();

  await page.goto("https://www.google.com/");
  await page.type("input[name='q']", "LinusU Marionette")
  await Future.wait([page.waitForNavigation(), page.click("input[type='submit']")]);

  page.dispose();
}

iOS

To be able to use Marionette on iOS, you need to give Marionette a hook to your view hierarchy. Otherwise the WKWebView will get suspended by the OS, and your Promises will never settle.

This is accomplished by using the setGlobalUIHook function before instantiating any Marionette instances.

Flutter:

If you have a non-modified Flutter application, this should be added to ios/Runner/AppDelegate.swift, in the application(_:didFinishLaunchingWithOptions:) function.

--- a/ios/Runner/AppDelegate.swift
+++ b/ios/Runner/AppDelegate.swift
@@ -1,5 +1,6 @@
 import UIKit
 import Flutter
+import flutter_marionette

 @UIApplicationMain
 @objc class AppDelegate: FlutterAppDelegate {
   override func application(
     _ application: UIApplication,
     didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
   ) -> Bool {
+    SwiftFlutterMarionettePlugin.setGlobalUIHook(window: UIApplication.shared.windows.first!)
     GeneratedPluginRegistrant.register(with: self)
     return super.application(application, didFinishLaunchingWithOptions: launchOptions)
   }

App:

// Can be called from anywhere, e.g. your AppDelegate
SwiftFlutterMarionettePlugin.setGlobalUIHook(window: UIApplication.shared.windows.first!)

App Extension:

// From within your root view controller
SwiftFlutterMarionettePlugin.setGlobalUIHook(viewController: self)

About

Marionette is a library which provides a high-level API to control a WebView

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 47.2%
  • Swift 20.6%
  • Dart 16.6%
  • Ruby 9.4%
  • Objective-C 3.9%
  • Java 2.3%