fix: tune the cloudflare logic to work with hcaptcha, remove timeout for the test possibly needing to solve a captcha

This commit is contained in:
Xymorot 2021-01-24 18:43:01 +01:00
parent 31945cac08
commit 8d6d7dc6d8
2 changed files with 11 additions and 4 deletions

View File

@ -1,9 +1,16 @@
import type { WebContents } from 'electron';
import ContentSecurityPolicy = Session.ContentSecurityPolicy;
/**
* @see https://docs.hcaptcha.com/#content-security-policy-settings
*/
export const cloudflareSiteCsp: ContentSecurityPolicy = {
'style-src': ['cdnjs.cloudflare.com'],
'script-src': ['hcaptcha.com'],
'style-src': ['cdnjs.cloudflare.com', 'https://hcaptcha.com', 'https://*.hcaptcha.com'],
'script-src': ['https://hcaptcha.com', 'https://*.hcaptcha.com'],
'script-src-elem': ['https://hcaptcha.com', 'https://*.hcaptcha.com'],
'frame-src': ['https://hcaptcha.com', 'https://*.hcaptcha.com'],
'connect-src': ['https://hcaptcha.com', 'https://*.hcaptcha.com'],
'img-src': ['https://hcaptcha.com', 'https://*.hcaptcha.com'],
};
export function humanInteractionRequired(webContents: WebContents): Promise<boolean> {
@ -14,6 +21,6 @@ export function humanInteractionRequired(webContents: WebContents): Promise<bool
export function isCloudFlareSite(webContents: WebContents): Promise<boolean> {
return webContents.executeJavaScript(
"!!document.querySelector('.cf-browser-verification, #cf-content')"
"!!document.querySelector('.cf-browser-verification, #cf-content, #cf-wrapper') || !!window._cf_translation"
) as Promise<boolean>;
}

View File

@ -61,5 +61,5 @@ describe('Nhentai App Window', () => {
};
gallery = await nhentaiAppWindow.getGallery('273405');
expect(gallery).deep.equalInAnyOrder(expectedGallery, 'The Archdemon in Love is not got correctly!');
}).timeout(5000);
}).timeout(0);
});