hlwhl / webview_cef

WebView for Flutter Desktop Apps using CEF(Chromium Embedded Framework) [Work in Progress]
Apache License 2.0
189 stars 54 forks source link
cef flutter flutter-desktop flutter-macos flutter-plugin flutter-windows macos webview windows

WebView CEF

Pub.dev likes Pub.dev points latest version Platform

Flutter Desktop WebView backed by CEF (Chromium Embedded Framework). This project is under heavy development, and the APIs are not stable yet.

Index

Supported OSs

Setting Up

Windows

Inside your application folder, you need to add some lines in your windows\runner\main.cpp.(Because of Chromium multi process architecture, and IME support, and also flutter rquires invoke method channel on flutter engine thread)

//Introduce the source code of this plugin into your own project
#include "webview_cef/webview_cef_plugin_c_api.h"

int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
                      _In_ wchar_t *command_line, _In_ int show_command) {
  //start cef deamon processes. MUST CALL FIRST
  initCEFProcesses();
  ::MSG msg;
  while (::GetMessage(&msg, nullptr, 0, 0)) {
    ::TranslateMessage(&msg);
    ::DispatchMessage(&msg);

    //add this line to enable cef keybord input, and enable to post messages to flutter engine thread from cef message loop thread.
    handleWndProcForCEF(msg.hwnd, msg.message, msg.wParam, msg.lParam);
  }

When building the project for the first time, a prebuilt cef bin package (200MB, link in release) will be downloaded automatically, so you may wait for a longer time if you are building the project for the first time.

macOS

To use the plugin in macOS, you'll need to clone the repository onto your project location, prefereably inside a packages/ folder on the root of your project. Update your pubspec.yaml file to accomodate the change.

...

dependencies:
  # Webview
  webview_cef:
    path: ./packages/webview_cef     # Or wherever you cloned the repo

...

Then follow the below steps inside the macos/ folder of the cloned repository.

  1. Download prebuilt cef bundles from arm64 or intel depends on your target machine arch.

Note: You can also download universal binary for build an mac-universal app if you want to build an mac universal app. See #30. Thanks to @okiabrian123.

  1. Unzip the archive and put all files into macos/third/cef. (Inside the cloned repository, not your project)

  2. Run the example app.



[HELP WANTED!] Finding a more elegant way to distribute the prebuilt package.

Note: Currently the project has not been enabled with multi process support due to debug convenience. If you want to enable multi process support, you may want to enable multi process mode by changing the implementation and build your own helper bundle. (Finding a more elegant way in the future.)

Linux

For Linux, just adding webview_cef to your pubspec.yaml (e.g. by running flutter pub add webview_cef) does the job.

TODOs

Pull requests are welcome.

Demo

This demo is a simple webview app that can be used to test the webview_cef plugin.

demo_compressed

Screenshots

Windows macOS Linux
image

Credits

This project is inspired from flutter_webview_windows.