Skip to content

Instantly share code, notes, and snippets.

@prescience-data
prescience-data / type-into.ts
Last active September 8, 2023 00:38
Demo of biometric typing skeleton logic for Playwright
import { chromium, Page } from "playwright-core"
/**
* Entrypoint.
*
* @remarks
* Demonstrates a safe typing algorithm that mimics human typing cadence.
*
* @public
*/
@prescience-data
prescience-data / compose.ts
Last active April 7, 2023 07:44
Typesafe composition
/**
* This is a test to show how to compose objects with typescript.
*/
/**
* Creates an intersection type from a union type.
* @public
*/
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
k: infer I
@prescience-data
prescience-data / queue.ts
Last active November 25, 2022 01:47
Simple Queue
/** Types **/
type JobId = string
type JobHandler<T> = () => Promise<T>
interface Job<T = any> {
id: JobId
handle: JobHandler<T>
locked: boolean
result?: any
}
@prescience-data
prescience-data / eslint-common.ts
Last active August 27, 2022 01:52
WebStorm ESLint 8 Plugin
export function containsString(src: string | null | undefined, toFind: string): boolean {
return src != null && src.indexOf(toFind) >= 0
}
export function normalizePath(eslintPackagePath: string | undefined): string | undefined {
if (eslintPackagePath === undefined) return undefined
if (eslintPackagePath.charAt(eslintPackagePath.length - 1) !== '/' &&
eslintPackagePath.charAt(eslintPackagePath.length - 1) !== '\\') {
eslintPackagePath = eslintPackagePath + '/';
}
@prescience-data
prescience-data / scroll-to-element.ts
Created March 8, 2022 23:14
Puppeteer Scroll To Element
import { randomInt } from "node:crypto"
import type Puppeteer from "puppeteer-core"
/** Recast Puppeteer private properties **/
type Page = Omit<Puppeteer.Page, "_client"> & {
readonly _client: Puppeteer.CDPSession
}
type ElementHandle = Omit<Puppeteer.ElementHandle, "_page"> & {
@prescience-data
prescience-data / strip-page.ts
Last active September 25, 2024 05:21
Strip Page With Puppeteer
import { Buffer } from "buffer"
import { createHash } from "crypto"
import { HTTPRequest, Protocol } from "puppeteer-core"
import { isPuppeteerPage, Page } from "../types"
type CaptureSnapshotResponse = Protocol.DOMSnapshot.CaptureSnapshotResponse
type RequestHook = (request: HTTPRequest) => Promise<void>
@prescience-data
prescience-data / download-chrome.ts
Created December 8, 2021 00:20
Download most recent Chrome build
import { createWriteStream, ensureDir } from "fs-extra"
import got from "got"
import { Stream } from "stream"
export type Platform =
| "Win_x64"
| "Win"
| "Mac"
| "Mac_Arm"
| "Linux_x64"
@prescience-data
prescience-data / recaptcha-signup.js
Last active June 13, 2021 11:08
recaptcha demo
import puppeteer from "puppeteer-extra"
import recaptcha from "puppeteer-extra-plugin-recaptcha"
/**
* Install the Recaptcha Plugin
*/
puppeteer.use(
recaptcha({
provider: {
id: "2captcha",
@prescience-data
prescience-data / hcaptcha.ts
Created April 15, 2021 09:12
HCaptcha Solver
import { IncomingMessage, RequestListener, ServerResponse } from "http"
import { createServer, Server } from "https"
import puppeteer, {
Browser,
BrowserLaunchArgumentOptions,
Protocol
} from "puppeteer-core"
import { Page } from "./types"
import Cookie = Protocol.Network.Cookie
@prescience-data
prescience-data / BotcheckActor.js
Created June 26, 2020 22:39
Puppeteer bot detection tests
/** namespace App\Actors **/
const Actor = require('./Actor');
class BotcheckActor extends Actor {
platform = 'botcheck';
constructor(env) {
const config = require('../../config/actors/botcheck');