Use a custom protocol when loading HTML#71
Merged
just-be-dev merged 5 commits intomainfrom Sep 29, 2024
Merged
Conversation
3fcab10 to
0373e4a
Compare
d4644d4 to
d89bcfd
Compare
When using `html` as an option for constructing a webview, you may want to have a finer grained control over the origin. This change allows you to specify the origin both during creation of the webview and at `load_html` time.
d89bcfd to
5cc3d7c
Compare
36f1d42 to
c920e7f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #70
When I first reported tauri-apps/wry#1367, @amrbashir recommended I use a custom protocol instead of
with_html. I hadn't experimented enough with custom protocols at the time and didn't real understand the tradeoffs between that anwith_html. The challenge with usingwith_htmlis that theoriginis null which means the page is considered to be in an insecure context. That disables a lot of features (like clipboard, noted in #70). The other challenge withwith_htmlis that when you reload you lose the contents of the page (which is what tauri-apps/wry#1367 was all about). I'd implementedload_htmlin tauri-apps/wry#1368, but that really doesn't get around the other problems ofwith_html.This PR implements a custom protocol called
load-html://. The request itself is ignored, it's just used to trigger the protocol load. There's aRefCellin the scope of the process where the HTML is cached. When the webview is initialized withhtml, that initial HTML string is loaded into the ref cell and the webview is initialized with the urlload-html://init. Likewise, whenwebview.loadHtmlis called, it sets the refcell and loadsload-html://load/<id>.