Skip to content

Applies to Cowork 0.1.45 · For everyone who uses Cowork

Site Requests ​

Not yet released

Lets a background task call a website's API with the login of a Cowork tab on that site. When no tab is open there, Cowork opens one in the background. Cowork sends the request from that tab; no cookie, token or header ever reaches the Extension. Only the sites, methods and paths listed in dozin.sites are allowed.

dozin.sites ​

FieldTypeRequiredDescription
hoststringYesLowercase host name, no scheme, port or path
methodsstring[]YesAny of GET, POST, PUT, PATCH, DELETE
pathPrefixesstring[]Yes1–16 paths a request must start with
minIntervalMsnumberNoLeast time between two requests to this host; default 1000, at most 60000

ctx.site.request(request) Not yet released ​

NameTypeRequiredDescription
request.hoststringYesA host from dozin.sites
request.methodstringNoDefault GET
request.pathstringYesStarts with / and with one of pathPrefixes; no ?, #, ..
request.queryRecord<string, string | number | boolean>NoOne value per key
request.bodyunknownNoJSON body; not allowed with GET

Returns ​

Promise<{ status: number, contentType: string | null, body: unknown }>. body is parsed JSON when the response is JSON.

Errors ​

The promise rejects with an error whose code is:

codeMeaning
NEED_LOGINCowork could not open a tab on that site, or the site answered that the person is not logged in
SITE_NOT_ALLOWEDHost, method or path not in dozin.sites
RATE_LIMITEDThe site answered 429
NETWORK_ERRORThe request did not reach the site
BAD_REQUESTInvalid query or body, a body with GET, or arguments that cannot be sent to Cowork
RUN_ENDEDThe run that made the call has ended

ctx.site.session(host) Not yet released ​

Tells whether the person seems logged in on that site.

NameTypeRequiredDescription
hoststringYesA host from dozin.sites

Returns Promise<{ loggedIn: boolean | null }>: the result of the last request to that site when there is one; otherwise null when a tab on the site is open (Cowork cannot tell yet) and false when none is.

Example ​

js
const { loggedIn } = await ctx.site.session('welladjustedhk.janeapp.com');
if (loggedIn === false) return ctx.status('Please log in to Jane', 'warn');
try {
  const res = await ctx.site.request({ host: 'welladjustedhk.janeapp.com', path: '/admin/api/v2/locations' });
  ctx.status(`OK · HTTP ${res.status}`);
} catch (error) {
  ctx.status(error.code === 'NEED_LOGIN' ? 'Please log in to Jane' : `Error: ${error.code}`, 'error');
}

For Micromeet Cowork 0.1.41 · build 261111110020