new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Playwright · API reference · all subjects

apirequest/apirequestcontext

5 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

APIRequestContext HTTP methods - get, post, put, patch, delete, head, fetch

APIRequestContext provides the following HTTP methods for making API requests: get(), post(), put(), patch(), delete(), head(), and fetch(). All methods are async and return APIResponse. All methods populate request cookies from the context, update context cookies from the response, and automatically follow redirects.

APIRequestContext cookie management

APIRequestContext returned by BrowserContext.request and Page.request uses the same cookie jar as its BrowserContext. Outgoing API requests automatically include the context's cookies in the Cookie header. Set-Cookie headers in API responses are written back to the BrowserContext. Logging in via the API logs in the browser, and vice versa. To create isolated requests without browser cookies, create a standalone APIRequestContext via APIRequest.newContext().

APIRequestContext access from BrowserContext and Page

Each Playwright browser context has an associated APIRequestContext accessible via BrowserContext.request or Page.request. These properties return the same instance — page.request is a shortcut for page.context().request. A standalone isolated instance can be created with APIRequest.newContext().

APIRequestContext example - GitHub API with cookies

Example demonstrating APIRequestContext usage with GitHub API: ```python import os import asyncio from playwright.async_api import async_playwright, Playwright REPO = "test-repo-1" USER = "github-username" API_TOKEN = os.getenv("GITHUB_API_TOKEN") async def run(playwright: Playwright): browser = await playwright.chromium.launch() context = await browser.new_context(base_url="https://api.github.com") api_request_context = context.request page = await context.new_page() # Create a repository response = await api_request_context.post( "/user/repos", headers={ "Accept": "application/vnd.github.v3+json", "Authorization": f"token {API_TOKEN}", }, data={"name": REPO}, ) assert response.ok assert response.json()["name"] == REPO # Delete a repository response = await api_request_context.delete( f"/repos/{USER}/{REPO}", headers={ "Accept": "application/vnd.github.v3+json", "Authorization": f"token {API_TOKEN}", }, ) assert response.ok assert await response.body() == '{"status": "ok"}' ``` Demonstrates making authenticated API requests that share cookies with browser context.

APIRequestContext response memory storage

All responses returned by APIRequestContext methods (get, post, fetch, etc.) are stored in memory so that you can later call APIResponse.body(). The dispose() method discards all resources.

Give your agent this brain

apirequest/apirequestcontext — Playwright · API reference