Playwright icon

Playwright

Automate browser actions using Playwright

Close Session

AI-generated

Summary

Closes a Playwright browser session held in the node's in-memory session store, disconnecting the remote browser and removing the session. Returns whether a session was found and closed.

Inputs

  • closeSessionId — ID of the session to close. If empty, the node uses the sessionKey propagated from the incoming item's json.playwright.sessionKey. If neither is available, a new random UUID is generated, which matches no session, so nothing is closed.
  • browser — Browser type selector (Firefox or Chrome). It is shown in the UI but not used when closing a session.
  • browserOptions.sessionId — Not shown for this operation, so it can't be set in the UI. Close Session uses closeSessionId and the propagated key instead.

Output shape

One item per input item, with json { success: boolean, sessionKey: string, message: 'Session closed' | 'No session found' }. Each item is paired to its input item.

success is false with 'No session found' if the key isn't in the store. This includes sessions already disconnected, a different n8n process or restart, or a wrong ID. success is also false if the browser.close() call throws. The session is removed from the store either way. With Continue On Fail enabled, errors return json.error plus playwright.sessionKey. The item does not carry forward json.playwright metadata, and no connection to the browser is opened.

Examples

Example 1: Clean up after a chain of Playwright nodes that kept the session open.

Place Close Session directly after the last Playwright node and leave Session ID To Close empty. It closes the propagated session.

Example 2: Close a session after a non-Playwright node, such as a Set or Code node, has dropped the metadata.

Set Session ID To Close to an expression like {{ $('Playwright').item.json.playwright.sessionKey }}.

Links

Discussion