Skip to content

Commit

Permalink
improve no video src error, add comment, add example/test
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewHerbst committed Dec 25, 2024
1 parent 137f1e7 commit 7c00d64
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions examples/ComponentToPrint/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ export const ComponentToPrint = React.forwardRef<HTMLDivElement | null, Componen
/>
</td>
</tr>
<tr>
<td>Video: Without src</td>
<td>
<video
width="200"
/>
</td>
</tr>
</tbody>
</table>
<div ref={shadowRootHostEl}/>
Expand Down
6 changes: 5 additions & 1 deletion src/utils/handlePrintWindowOnLoad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ export function handlePrintWindowOnLoad(
if (videoNode.readyState >= 2) { // Check if the video has already loaded a frame
markLoaded(videoNode);
} else if (!videoNode.src) {
markLoaded(videoNode, ["video src empty", videoNode, "Error"]);
// There are scenarios where `src` can be empty, for example, if it was defined
// incorrectly or lazy loaded in some manner. This is unexpected, but we should
// handle it to ensure printing can continue if this is encountered.
// See https://github.com/MatthewHerbst/react-to-print/pull/772
markLoaded(videoNode, ["Error loading video, `src` is empty", videoNode]);
} else{
videoNode.onloadeddata = () => {
markLoaded(videoNode)
Expand Down

0 comments on commit 7c00d64

Please sign in to comment.