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

Screenshots in wasm #8455

Merged
merged 4 commits into from
Apr 28, 2023
Merged

Screenshots in wasm #8455

merged 4 commits into from
Apr 28, 2023

Conversation

mockersf
Copy link
Member

Objective

Solution

  • Create a blob from the image data, generate a url to that blob, add an a element to the document linking to that url, click on that element, then revoke the url
  • This will automatically trigger a download of the screenshot file in the browser

@mockersf mockersf added the O-Web Specific to web (WASM) builds label Apr 22, 2023
Copy link
Contributor

@nicopap nicopap left a comment

Choose a reason for hiding this comment

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

LGTM. just a question

html_element.click();
web_sys::Url::revoke_object_url(&url)?;
Ok::<(), JsValue>(())
})() {
Copy link
Contributor

Choose a reason for hiding this comment

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

The syntax for "try/catch" in rust is very unusual 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

you... get used to it. and it provides nice scoping

crates/bevy_render/src/view/window/screenshot.rs Outdated Show resolved Hide resolved
@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Rendering Drawing game state to the screen A-Diagnostics Logging, crash handling, error reporting and performance analysis labels Apr 22, 2023
Comment on lines +86 to +95
'Blob',
'Document',
'Element',
'HtmlElement',
'Node',
'Url',
'Window',
Copy link
Member

Choose a reason for hiding this comment

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

Will including more web-sys features meaningfully affect our wasm build sizes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just tried a build, it's 14kB smaller with this PR. Build duration were similar

Copy link
Member

Choose a reason for hiding this comment

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

Amazing that it got smaller by adding features. Works for me

@cart cart added this pull request to the merge queue Apr 28, 2023
Merged via the queue into bevyengine:main with commit cb286e5 Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Diagnostics Logging, crash handling, error reporting and performance analysis A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible O-Web Specific to web (WASM) builds
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants