export type CreateApiSessionsSessionIdDeviceTakeScreenshotArgs = {sessionId: string}; export type CreateApiSessionsSessionIdDeviceTakeScreenshotOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Take a screenshot from device * * POST /sessions/{sessionId}/device/takeScreenshot */ export const createApiSessionsSessionIdDeviceTakeScreenshot = async (args: CreateApiSessionsSessionIdDeviceTakeScreenshotArgs, options?: CreateApiSessionsSessionIdDeviceTakeScreenshotOptions) => { const {baseUrl = "https://api.us-west-1.saucelabs.com/rdc/v2", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "image/png") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/sessions/${encodeURIComponent(String(args.sessionId))}/device/takeScreenshot${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };