@laneshot/sdk has two parts:
- The API client,
@laneshot/sdk, for Node.js, Bun, Deno, edge runtimes, and scripts. It reads captures, cards, and automations, creates cards, and uploads captures through the REST API. - The browser module,
@laneshot/sdk/browser, for your own web app. It adds context, such as the signed-in user or the release, to the captures people take on your site. See App metadata.
The package is MIT-licensed, has no runtime dependencies, and ships ES modules with TypeScript types.
Install
npm install @laneshot/sdk
The client uses the global fetch, available in Node.js 20 and later, Bun, Deno, and every modern runtime.
Create a client
import { Laneshot } from "@laneshot/sdk";
const laneshot = new Laneshot({
baseUrl: "https://laneshot.acme.test",
token: process.env.LANESHOT_TOKEN,
});
| Option | Type | Description |
|---|---|---|
baseUrl |
string | Required. Your Laneshot address. Trailing slashes are removed. |
token |
string | An API token starting with lsh_. See Create a token. Leave it out to read public share links only. |
fetch |
function | A custom fetch, for example one that goes through a proxy or records requests in tests. |
The token acts as the person who created it, with their access, inside the one organization it belongs to. Keep it on the server: never ship it in browser code.
Read a capture
Every capture method takes a trace ID, a private link (/traces/…), a public link (/share/…), or a share token, so you can pass whatever someone pasted.
const link = "https://laneshot.acme.test/traces/7c1e4f2a-93b8-4d55-a0e1-2f6b9d3c8a17";
const trace = await laneshot.traces.get(link);
console.log(trace.title, trace.card?.reference);
// Card payment fails with 3-D Secure on Safari SHOP-3
const errors = await laneshot.traces.consoleLogs(link, { errorsOnly: true });
for (const error of errors) console.log(error.message);
// Payment failed: upstream_timeout
const failed = await laneshot.traces.networkRequests(link, { failedOnly: true });
for (const request of failed) {
console.log(request.status, request.method, request.url, request.backendTraceId);
}
// 502 POST https://shop.acme.test/api/payments/confirm 4bf92f3577b34da6a3ce929d0e0e4736
To hand a capture to an AI model, use the Markdown report. It contains the description, environment, app metadata, errors, failed requests with bodies, actions, transcript, and backend telemetry in one document:
const report = await laneshot.traces.markdown(link);
Reference
Client
| Method | Returns | Description |
|---|---|---|
me() |
{ user, organization, organizations, projects } |
The token's owner, the organization the token belongs to, every organization they're in, and the projects where they can attach captures, with their columns. GET /me |
request(path, init?) |
Response |
Calls any API path with the token, and throws LaneshotError on failure. Use it for endpoints without a helper. |
Projects
| Method | Returns | Description |
|---|---|---|
projects.list() |
Project[] |
Projects you can open: id, key, name. GET /projects |
Cards
| Method | Returns | Description |
|---|---|---|
cards.search(projectId, query?) |
CardSummary[] |
Up to 20 cards whose title contains query or whose number matches it, most recently updated first. GET /projects/:id/cards |
cards.get(reference) |
Card |
A card from its reference, such as SHOP-3, with labels, linked issues, comments, and captures. GET /cards/:reference |
cards.create(projectId, input) |
CreatedCard |
Creates a card. input: title (required), description, type (task, story, bug), priority (low, medium, high, urgent), columnId. Returns id, number, reference, url. POST /projects/:id/cards |
const created = await laneshot.cards.create("3f2c9a1e-7b4d-4c1a-9e2f-5a6b7c8d9e01", {
title: "Apple Pay sheet closes immediately on iOS 18",
type: "bug",
priority: "high",
});
console.log(created.reference); // SHOP-14
Traces
| Method | Returns | Description |
|---|---|---|
traces.list(options?) |
TraceListItem[] |
Recent captures, newest first. options: projectId, limit (up to 100, default 20). GET /traces |
traces.get(trace) |
Trace |
Metadata: description, environment with appMetadata, summary, card, shareUrl, transcriptStatus. GET /traces/:trace |
traces.events(trace, filter?) |
TraceEvent[] |
The timeline, oldest first. filter: kinds, errorsOnly, failedOnly, includeAssets, urlContains, limit (up to 5,000, default 500). GET /traces/:trace/events |
traces.consoleLogs(trace, options?) |
ConsoleEvent[] |
Console output. options: errorsOnly, limit. |
traces.networkRequests(trace, options?) |
NetworkEvent[] |
Requests, without assets unless includeAssets is set. options: failedOnly, urlContains, includeAssets, limit. |
traces.markdown(trace) |
string |
The whole capture as Markdown. GET /traces/:trace/markdown |
traces.transcript(trace) |
Transcript | null |
Timed segments of what the person said, or null. GET /traces/:trace/transcript |
traces.upload(input, onStep?) |
{ id, url } |
Uploads a capture in the four API steps. See Upload a capture. |
TraceEvent is a union discriminated by kind: console, network, action, navigation, socket, or page. The fields of each kind are listed in List events.
Automations
| Method | Returns | Description |
|---|---|---|
automations.list(projectId) |
Automation[] |
id, name, trigger, enabled. GET /projects/:id/automations |
automations.run(id, options?) |
AutomationRun |
Runs it now, optionally on { card: "SHOP-3" }, and returns status and each step. POST /automations/:id/run |
const run = await laneshot.automations.run("a7b8c9d0-e1f2-4a3b-9c4d-5e6f7a8b9c0d", {
card: "SHOP-3",
});
if (run.status !== "succeeded") {
const failed = run.steps.find((step) => step.status === "failed");
throw new Error(`${failed?.label}: ${failed?.detail}`);
}
Helpers
| Export | Description |
|---|---|
traceRef(input) |
Turns an ID, private link, public link, or share token into the identifier the API expects. |
LaneshotError |
The error every method throws. See Errors. |
| Types | Project, Card, CardSummary, NewCard, CreatedCard, Trace, TraceListItem, TraceEnvironment, TraceSummary, TraceEvent, ConsoleEvent, NetworkEvent, EventFilter, Transcript, TraceUpload, TraceAttachment, Automation, AutomationRun, and more. |
Upload a capture
traces.upload registers the capture, sends its events, sends its media, then completes it, exactly like the browser extension.
import { readFile } from "node:fs/promises";
const { url } = await laneshot.traces.upload(
{
kind: "screenshot",
media: new Blob([await readFile("test-results/checkout-failed.png")], { type: "image/png" }),
title: "e2e: checkout › pays with a saved card",
description: "Failed on main, run 4812.",
environment: {
url: "https://staging.shop.acme.test/checkout/payment",
title: "Payment · Acme Storefront",
userAgent: "Playwright/1.56 Chromium/141",
browser: { name: "Chromium", version: "141" },
os: { name: "Linux", version: "" },
viewport: { width: 1280, height: 720 },
screen: { width: 1280, height: 720, devicePixelRatio: 1 },
language: "en-US",
timezone: "UTC",
colorScheme: "light",
},
attachment: { type: "new-card", projectId: "3f2c9a1e-7b4d-4c1a-9e2f-5a6b7c8d9e01" },
},
(step) => console.log(step), // creating, events, media, completing
);
| Field | Description |
|---|---|
kind |
video (video/webm, video/mp4), screenshot (image/png, image/jpeg), or replay (rrweb events as application/json). The media type must match. |
media |
A Blob with the right type. |
environment |
Page and browser details. Required fields are listed in Register the capture. |
events |
Optional timeline. Defaults to an empty list. |
startedAt |
Unix milliseconds. Defaults to now. |
durationMs |
Defaults to 0. |
attachment |
{ type: "card", cardId } or { type: "new-card", projectId, columnId? }. Leave it out to keep the capture in your library. |
If a step fails, the method throws and the capture stays incomplete and private. Call upload again: it starts a new capture.
Errors
Every method throws a LaneshotError when a request fails. It has the server's message and the HTTP status, which is 0 when the server can't be reached at all:
import { LaneshotError } from "@laneshot/sdk";
try {
await laneshot.cards.get("SHOP-999");
} catch (error) {
if (error instanceof LaneshotError && error.status === 404) {
console.log(error.message); // Card not found.
} else {
throw error;
}
}
The statuses and their meanings are listed in REST API errors.
Public links without a token
A client without a token can read captures that have a public link: traces.get, traces.events, traces.consoleLogs, traces.networkRequests, traces.markdown, and traces.transcript.
const anonymous = new Laneshot({ baseUrl: "https://laneshot.acme.test" });
const report = await anonymous.traces.markdown(
"https://laneshot.acme.test/share/share_kX2pQ9vLm3",
);
Browser module
Add the signed-in user, the release, and anything else your team needs to every capture taken on your site:
import { setMetadata, setUser } from "@laneshot/sdk/browser";
setUser({ id: account.id, email: account.email, plan: account.plan });
setMetadata(() => ({ release: __RELEASE__, flags: activeFlags() }));
| Export | Description |
|---|---|
setUser(user | null) |
Sets who is signed in. It appears as user in the metadata. Pass null on sign-out. |
setMetadata(provider) |
Adds a function, sync or async, called when someone captures a bug, or a plain object. Returns a function that removes it. Later providers override keys of earlier ones. |
clear() |
Removes the user and every provider. |
collectMetadata() |
Returns what the extension would read now. Useful in tests. |
The module sends nothing anywhere. The Laneshot extension reads the values only when someone captures a bug. How they're redacted, capped, and displayed is described in App metadata.
Recipes
Post new failures to your chat from a cron job
import { Laneshot } from "@laneshot/sdk";
const laneshot = new Laneshot({ baseUrl: process.env.LANESHOT_URL!, token: process.env.LANESHOT_TOKEN });
const since = Date.now() - 60 * 60 * 1000;
const traces = await laneshot.traces.list({ projectId: process.env.SHOP_PROJECT_ID, limit: 50 });
for (const trace of traces) {
if (new Date(trace.createdAt).getTime() < since) continue;
if (!trace.summary?.failedRequests) continue;
const failed = await laneshot.traces.networkRequests(trace.id, { failedOnly: true, limit: 3 });
console.log(`${trace.card?.reference ?? "No card"} ${trace.title}`);
for (const request of failed) console.log(` ${request.status} ${request.method} ${request.url}`);
}
For alerts on every capture, an automation with a webhook is simpler: it runs when the capture is uploaded, without polling.
Look up backend traces for a capture
Failed requests carry the W3C trace ID Laneshot added to them, which you can look up in your tracing tool:
const failed = await laneshot.traces.networkRequests(link, { failedOnly: true });
const ids = failed.map((request) => request.backendTraceId).filter(Boolean);
console.log(ids.map((id) => `https://grafana.acme.test/explore?traceId=${id}`));
When the project has a backend connection, the Markdown report already includes the matching spans, exceptions, and logs.
Troubleshooting
LaneshotError with status 0. The server couldn't be reached: check baseUrl, DNS, and that your network allows it. The message contains the underlying error.
TypeError: Pass the address of your Laneshot server. baseUrl is empty, often because an environment variable isn't set.
401 Invalid API token. The token was revoked or its owner was deactivated. Create a new one in Account settings.
404 Trace not found. for a link that opens in your browser. Your browser is signed in as you, but the token may belong to another account that can't open the capture. Public links work without a token.
Calls from a web page fail with a CORS error. The API is meant for servers and scripts. Use @laneshot/sdk/browser for context from your web app.