Skip to content

Commit

Permalink
Merge pull request #85 from Gyanreyer/fix/remove-crossorigin-default
Browse files Browse the repository at this point in the history
Remove default "anonymous" value for crossOrigin prop
  • Loading branch information
Gyanreyer authored Oct 5, 2022
2 parents 889d9f8 + b6b3f8d commit 7dfab5f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
10 changes: 6 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,17 @@ In practice this looks like:

### crossOrigin

**Type**: `string` | **Default**: `"anonymous"`
**Type**: `string` | **Default**: `null`

The `crossOrigin` prop maps directly to the [HTML Video element's crossorigin attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#attr-crossorigin) and allows us to define how the video element should handle CORS requests. For most purposes, you should not need to worry about setting this, but if you are having trouble with CORS a good first step may be to try setting it to `"anonymous"`.

The `crossOrigin` prop maps directly to the [HTML Video element's crossorigin attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#attr-crossorigin) and allows us to define how the video element should handle CORS requests. For most purposes, you should not need to worry about setting this. The acceptable values are:
The acceptable values are:

- `"anonymous"`: The video element will send cross-origin requests with no credentials. This is the browser default and usually all you need for most purposes.
- `"anonymous"`: The video element will send cross-origin requests with no credentials.
- `"use-credentials"`: The video element will send cross-origin requests with credentials.

```jsx
<HoverVideoPlayer videoSrc="video.mp4" crossOrigin="use-credentials" />
<HoverVideoPlayer videoSrc="video.mp4" crossOrigin="anonymous" />
```

## Overlays
Expand Down
2 changes: 1 addition & 1 deletion src/HoverVideoPlayer.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export interface HoverVideoPlayerProps
* This is the browser default and usually all you need for most purposes.
* - **"use-credentials"**: The video element will send cross-origin requests with credentials.
*
* @defaultValue "anonymous"
* @defaultValue null
*/
crossOrigin?: 'anonymous' | 'use-credentials';
/**
Expand Down
2 changes: 1 addition & 1 deletion src/component/HoverVideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function HoverVideoPlayer({
volume = 1,
loop = true,
preload = null,
crossOrigin = 'anonymous',
crossOrigin = null,
controls = false,
controlsList = null,
disableRemotePlayback = true,
Expand Down
10 changes: 3 additions & 7 deletions tests/cypress/component/videoAttributes.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,13 @@ describe('Sets attributes on the video element correctly', () => {
});

describe('crossOrigin', () => {
it('sets crossOrigin to anonymous by default', () => {
it('does not set crossOrigin by default', () => {
mount(<HoverVideoPlayer videoSrc={makeMockVideoSrc()} />);

cy.get(videoElementSelector).should(
'have.attr',
'crossorigin',
'anonymous'
);
cy.get(videoElementSelector).should('not.have.attr', 'crossorigin');
cy.get(videoElementSelector)
.invoke('prop', 'crossOrigin')
.should('eq', 'anonymous');
.should('be.null');
});

it('sets crossorigin on the video when the crossOrigin prop is set', () => {
Expand Down

0 comments on commit 7dfab5f

Please sign in to comment.