-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from emailjs-com/validate-headless
Block the headless browsers
- Loading branch information
Showing
13 changed files
with
213 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { it, expect } from '@jest/globals'; | ||
|
||
import { EmailJSResponseStatus } from '../../models/EmailJSResponseStatus'; | ||
import { headlessError } from './headlessError'; | ||
|
||
it('should return EmailJSResponseStatus', () => { | ||
expect(headlessError()).toBeInstanceOf(EmailJSResponseStatus); | ||
}); | ||
|
||
it('should return status 451', () => { | ||
expect(headlessError()).toEqual({ | ||
status: 451, | ||
text: 'Unavailable For Headless Browser', | ||
}); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { EmailJSResponseStatus } from '../../models/EmailJSResponseStatus'; | ||
|
||
export const headlessError = () => { | ||
return new EmailJSResponseStatus(451, 'Unavailable For Headless Browser'); | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export interface Options { | ||
origin?: string; | ||
publicKey?: string; | ||
blockHeadless?: boolean; | ||
limitRate?: number; | ||
blockList?: string[]; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { it, expect } from '@jest/globals'; | ||
import { isHeadless } from './isHeadless'; | ||
|
||
it('should be headless browser', () => { | ||
expect(isHeadless(navigator)).toBeTruthy(); | ||
}); | ||
|
||
it('should be headless browser without languages', () => { | ||
expect( | ||
isHeadless({ | ||
webdriver: false, | ||
} as Navigator), | ||
).toBeTruthy(); | ||
}); | ||
|
||
it('should be headfull browser', () => { | ||
expect( | ||
isHeadless({ | ||
webdriver: false, | ||
languages: ['un'], | ||
} as unknown as Navigator), | ||
).toBeFalsy(); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const isHeadless = (navigator: Navigator) => { | ||
return navigator.webdriver || !navigator.languages || navigator.languages.length === 0; | ||
}; |