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

fix: use frames for video capture & add iframes #346

Merged
merged 1 commit into from Dec 12, 2022

Conversation

DustinBrett
Copy link
Contributor

This pull request addresses the issue with capturing videos and iframes in the library, where the resulting images were blank or incorrect.

Description

To fix this issue, I have updated the cloneVideoElement and cloneIframeElement functions to use the contentDocument.body and canvas APIs to capture frames from the videos and iframes, and convert them to data URLs.

For videos, I have added a canvas element to the page, set its size to the same size as the video, and used the drawImage method to draw the video to the canvas. I have then used the canvas.toDataURL method to convert the canvas image to a data URL.

For iframes, I have used the contentDocument property of the HTMLIFrameElement to access the document object of the iframe, and then used the querySelector method to find the video element of the iframe. I have then used the same approach as before to capture a frame from the video and convert it to a data URL.

I have also added error handling to the functions to catch any errors that may be thrown by these APIs, and added tests to verify that the fixes work as expected.

Please review and let me know if there are any changes needed. Thank you!

ChatGPT helped me

Motivation and Context

This is related to these issues

Video capture
#312
#202
#193

iFrame capture
#192
#167
#36

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Enhancement (changes that improvement of current feature or performance)
  • Refactoring (changes that neither fixes a bug nor adds a feature)
  • Test Case (changes that add missing tests or correct existing tests)
  • Code style optimization (changes that do not affect the meaning of the code)
  • Docs (changes that only update documentation)
  • Chore (changes that don't modify src or test files)

Self Check before Merge

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@vivcat
Copy link
Contributor

vivcat bot commented Dec 11, 2022

👋 @DustinBrett

💖 Thanks for opening this pull request! 💖

Please follow the contributing guidelines. And we use semantic commit messages to streamline the release process.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add graph.scale() method
  • docs: graph.getShortestPath is now available

Things that will help get your PR across the finish line:

  • Follow the TypeScript coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@bubkoo bubkoo self-requested a review December 12, 2022 06:37
Copy link
Owner

@bubkoo bubkoo left a comment

Choose a reason for hiding this comment

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

LGTM

@bubkoo bubkoo merged commit e316c61 into bubkoo:master Dec 12, 2022
@vivcat
Copy link
Contributor

vivcat bot commented Dec 12, 2022

👋 @DustinBrett Congrats on merging your first pull request! 🎉🎉🎉

github-actions bot pushed a commit that referenced this pull request Dec 13, 2022
## [1.11.2](v1.11.1...v1.11.2) (2022-12-13)

### Bug Fixes

* fallback to `poster` when `currentSrc` of video is null ([5d79666](5d79666))
* use frames for video capture & add iframes ([#346](#346)) ([e316c61](e316c61))
@vivcat
Copy link
Contributor

vivcat bot commented Dec 13, 2022

🎉 This PR is included in version 1.11.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@vivcat vivcat bot added the released label Dec 13, 2022
@haodaking
Copy link

iframe css not working

@DustinBrett
Copy link
Contributor Author

iframe css not working

Yes it does have some limitations currently I'd noticed. Same with images. I think it needs it's base url to be from the iframe. If you have a suggestion where to tweak it please PR.

@haodaking
Copy link

#351
This is my first pr submission, my english is not very good, sorry

iframe css not working

Yes it does have some limitations currently I'd noticed. Same with images. I think it needs it's base url to be from the iframe. If you have a suggestion where to tweak it please PR.

@DustinBrett
Copy link
Contributor Author

#351 This is my first pr submission, my english is not very good, sorry

iframe css not working

Yes it does have some limitations currently I'd noticed. Same with images. I think it needs it's base url to be from the iframe. If you have a suggestion where to tweak it please PR.

I see the problem now from your solution. I have a fix in general I'm also interested in possibly PR'ing. I think instanceof is not a reliable way to check if it's a type of element. I wrote a recursive function that can compare the prototype properly and seems to be working. But I need to do more testing.

istaiti pushed a commit to inscreen/html-to-image that referenced this pull request Feb 7, 2023
istaiti pushed a commit to inscreen/html-to-image that referenced this pull request Feb 7, 2023
## [1.11.2](bubkoo/html-to-image@v1.11.1...v1.11.2) (2022-12-13)

### Bug Fixes

* fallback to `poster` when `currentSrc` of video is null ([5d79666](bubkoo@5d79666))
* use frames for video capture & add iframes ([bubkoo#346](bubkoo#346)) ([e316c61](bubkoo@e316c61))
istaiti pushed a commit to inscreen/html-to-image that referenced this pull request Feb 7, 2023
istaiti pushed a commit to inscreen/html-to-image that referenced this pull request Feb 7, 2023
## [1.11.2](bubkoo/html-to-image@v1.11.1...v1.11.2) (2022-12-13)

### Bug Fixes

* fallback to `poster` when `currentSrc` of video is null ([5d79666](bubkoo@5d79666))
* use frames for video capture & add iframes ([bubkoo#346](bubkoo#346)) ([e316c61](bubkoo@e316c61))
istaiti pushed a commit to inscreen/html-to-image that referenced this pull request Feb 7, 2023
istaiti pushed a commit to inscreen/html-to-image that referenced this pull request Feb 7, 2023
## [1.11.2](bubkoo/html-to-image@v1.11.1...v1.11.2) (2022-12-13)

### Bug Fixes

* fallback to `poster` when `currentSrc` of video is null ([5d79666](bubkoo@5d79666))
* use frames for video capture & add iframes ([bubkoo#346](bubkoo#346)) ([e316c61](bubkoo@e316c61))
istaiti pushed a commit to inscreen/html-to-image that referenced this pull request Feb 7, 2023
istaiti pushed a commit to inscreen/html-to-image that referenced this pull request Feb 7, 2023
## [1.11.2](bubkoo/html-to-image@v1.11.1...v1.11.2) (2022-12-13)

### Bug Fixes

* fallback to `poster` when `currentSrc` of video is null ([5d79666](bubkoo@5d79666))
* use frames for video capture & add iframes ([bubkoo#346](bubkoo#346)) ([e316c61](bubkoo@e316c61))
istaiti pushed a commit to inscreen/html-to-image that referenced this pull request Feb 7, 2023
istaiti pushed a commit to inscreen/html-to-image that referenced this pull request Feb 7, 2023
## [1.11.2](bubkoo/html-to-image@v1.11.1...v1.11.2) (2022-12-13)

### Bug Fixes

* fallback to `poster` when `currentSrc` of video is null ([5d79666](bubkoo@5d79666))
* use frames for video capture & add iframes ([bubkoo#346](bubkoo#346)) ([e316c61](bubkoo@e316c61))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants