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

feat: Add a way to launch WebViews as incognito WebView::as_incognito, closes #908 #916

Merged
merged 28 commits into from
Apr 6, 2023

Conversation

Hyphrio
Copy link
Contributor

@Hyphrio Hyphrio commented Mar 29, 2023

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Docs
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes
  • No

Checklist

Other information

This adds an option for WebViewBuilder to allow launching a WebView on incognito mode, to allow for things that would need epheremal instances, such as webview sign-ins.

@Hyphrio
Copy link
Contributor Author

Hyphrio commented Mar 29, 2023

Currently I only implemented this on Windows and WebKitGTK, I don't have a Mac or an iPhone so I can't do WKWebView that would be guaranteed to work and my computer is too slow to implement Android.

@Hyphrio Hyphrio marked this pull request as ready for review April 1, 2023 09:36
@Hyphrio Hyphrio requested a review from a team as a code owner April 1, 2023 09:36
@Hyphrio
Copy link
Contributor Author

Hyphrio commented Apr 1, 2023

Android would be unsupported as incognito mode would have to be called on the destructors and the non-destructor API is depreciated.

Only thing now is I hope MacOS functionality could be verified as working as I can't test it.

@wusyong
Copy link
Member

wusyong commented Apr 3, 2023

@Hyphrio It's okay to leave Android unsupported. Thank you for the work! I'll test them all once I get back.

Btw I can't figure out how your example works. Can you elaborate?

@Hyphrio
Copy link
Contributor Author

Hyphrio commented Apr 4, 2023

Uh the example is unfortunately still broken (on Windows) because of read-only access on the HTML file, I'll probably just spin up a temp HTTP server to work around that but that example just sets a cookie then when you close the window and reopen it it should attempt to load that cookie, but since it's incognito it will appear as nothing

EDIT: Example works on Linux Nevermind it doesn't

@Hyphrio
Copy link
Contributor Author

Hyphrio commented Apr 4, 2023

WebKitGTK impl is currently broken so I converted this back to draft

@Hyphrio Hyphrio marked this pull request as draft April 4, 2023 04:45
@Hyphrio Hyphrio marked this pull request as ready for review April 4, 2023 06:09
@Hyphrio
Copy link
Contributor Author

Hyphrio commented Apr 4, 2023

Hopefully Linux is fixed now (is_ephemeral was read-only, had to modify both WebContext and WebContextImpl to add a new function named new_ephemeral)

@pewsheen
Copy link
Contributor

pewsheen commented Apr 4, 2023

Hello @Hyphrio, I can help test if the Mac fix works.

So I just ran the incognito example, the solution with data store configuration works pretty well, but a few things need fixing.

The data store can be retrieved directly from the WKWebsiteDataStore class:

let data_store: id = msg_send![class!(WKWebsiteDataStore), defaultDataStore];
let data_store: id = msg_send![class!(WKWebsiteDataStore), nonPersistentDataStore];

And the data store can be set to WKWebViewConfiguration by calling setWebsiteDataStore from the configuration instance:

let () = msg_send![config, setWebsiteDataStore: data_store];

@Hyphrio
Copy link
Contributor Author

Hyphrio commented Apr 4, 2023

Alright @pewsheen thank you for the insight about WKWebView!

@wusyong
Copy link
Member

wusyong commented Apr 5, 2023

I want to make a note on Linux side. So the cookie is persist if we specify a web context even with incognito is enabled.
So I think it will have to skip creating webcontext if we want to use incognito mode.

I'll test macOS and windows later.

Edit: Windows seems great. So it's only macOS left.

Copy link
Member

@wusyong wusyong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with how this turns out. Thank you @Hyphrio!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Launch Webviews as incognito
3 participants