27 lines
1.2 KiB
TypeScript
27 lines
1.2 KiB
TypeScript
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', '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> {
|
|
return webContents.executeJavaScript(
|
|
"[...document.querySelectorAll('iframe')].map(iframe => (new URL(iframe.src)).hostname.match(/hcaptcha/)).some(e => e)"
|
|
) as Promise<boolean>;
|
|
}
|
|
|
|
export function isCloudFlareSite(webContents: WebContents): Promise<boolean> {
|
|
return webContents.executeJavaScript(
|
|
"!!document.querySelector('.cf-browser-verification, #cf-content, #cf-wrapper') || !!window._cf_translation"
|
|
) as Promise<boolean>;
|
|
}
|