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

Launch Webviews as incognito #908

Closed
1 of 2 tasks
Hyphrio opened this issue Mar 22, 2023 · 2 comments · Fixed by #916 or #919
Closed
1 of 2 tasks

Launch Webviews as incognito #908

Hyphrio opened this issue Mar 22, 2023 · 2 comments · Fixed by #916 or #919

Comments

@Hyphrio
Copy link
Contributor

Hyphrio commented Mar 22, 2023

Is your feature request related to a problem? Please describe.
For browser based OAuth where you cannot guarantee the existence of a web browser but can guarantee the existence of a WebView, having an option to launch a webview as incognito would be useful.

Would you want to assign yourself to implement this feature?

  • Yes
  • No

Other (I did a PoC for WebView2)

Additional context
On Windows, it could be done by modifying InnerWebView::create_controller to something like this:

  fn create_controller(
    hwnd: HWND,
    env: &ICoreWebView2Environment,
    incognito: bool
  ) -> webview2_com::Result<ICoreWebView2Controller> {
    let (tx, rx) = mpsc::channel();
    let env = env.clone().cast::<ICoreWebView2Environment10>()?;
    let controller_opts = unsafe {env.CreateCoreWebView2ControllerOptions()?};

    unsafe {controller_opts.SetIsInPrivateModeEnabled(incognito)?}

    CreateCoreWebView2ControllerCompletedHandler::wait_for_async_operation(
      Box::new(move |handler| unsafe {
        env
          .CreateCoreWebView2ControllerWithOptions(hwnd, &controller_opts, &handler)
          .map_err(webview2_com::Error::WindowsError)
      }),
      Box::new(move |error_code, controller| {
        error_code?;
        tx.send(controller.ok_or_else(|| windows::core::Error::from(E_POINTER)))
          .expect("send over mpsc channel");
        Ok(())
      }),
    )?;

    rx.recv()
      .map_err(|_| webview2_com::Error::SendError)?
      .map_err(webview2_com::Error::WindowsError)
  }

It would be needed to cast env to ICoreWebView2Environment10 first as ICoreWebView2Environment wouldn't have CreateCoreWebView2ControllerWithOptions.

@wusyong
Copy link
Member

wusyong commented Mar 23, 2023

webkit2gtk can enable it via SettingsExt trait.

@Hyphrio
Copy link
Contributor Author

Hyphrio commented Mar 26, 2023

Any idea for macOS/iOS and Android? I do have both Windows and WebKitGTK both implemented now (but I did have to use is_ephemeral on WebViewBuilder rather than enable_private_browsing to make the behavior more consistent like on Windows)

wusyong added a commit that referenced this issue Apr 6, 2023
…o`, closes #908 (#916)

* impl Incognito for WebKitGTK and WebView2

* Fix broken commit

* i hate objc

* Mark Android as unsupported

* fix broken webview2 module

* better example

* example currently broken

* forgot change file

* update

* Fix WebKitGTK

* Share same code when creating context

* Cargo fmt

* Clean gitignore

* Simply more code

* Small patches to WKWebView, thank you pewsheen!

* Fix example on Windows

* Fix an oversight on WKWebView

* Fix webkit2gtk implementation

* Rename to with_incognito

* Fix WKWebView type annotations

* Fix warnings on wkwebview

* Remove examples

We can test with existing sites instead.

* Update docs

* Cargo fmt

---------

Co-authored-by: Wu Yu Wei <[email protected]>
Co-authored-by: Wu Wayne <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants