export type CreateApiSessionsSessionIdDeviceOpenUrlArgs = {sessionId: string, body: {url: string}}; export type CreateApiSessionsSessionIdDeviceOpenUrlOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Open a url (through browser) or a deeplink to an app * * POST /sessions/{sessionId}/device/openUrl */ export const createApiSessionsSessionIdDeviceOpenUrl = async (args: CreateApiSessionsSessionIdDeviceOpenUrlArgs, options?: CreateApiSessionsSessionIdDeviceOpenUrlOptions) => { 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('content-type', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/sessions/${encodeURIComponent(String(args.sessionId))}/device/openUrl${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };