Skip to content

Fix cookie injection crash & add env var configuration#105

Open
NisargIO wants to merge 6 commits into
mainfrom
better
Open

Fix cookie injection crash & add env var configuration#105
NisargIO wants to merge 6 commits into
mainfrom
better

Conversation

@NisargIO
Copy link
Copy Markdown
Member

@NisargIO NisargIO commented May 6, 2026

Summary

  • Fix cookie crash: playwrightFormat no longer includes sameSite: undefined, which caused Protocol error (Storage.setCookies): Invalid cookie fields in Playwright
  • Per-cookie fallback: When batch addCookies fails, falls back to injecting cookies one-by-one so one bad cookie doesn't abort the rest
  • New env vars: EXPECT_COOKIES (simple on/off toggle) and EXPECT_BROWSER (default engine) for MCP configuration

Test plan

  • Run with EXPECT_COOKIES=true against a site that previously crashed with Invalid cookie fields
  • Verify partial cookie sync works (some cookies injected even if others are invalid)
  • Verify EXPECT_BROWSER=webkit changes the default browser engine

Made with Cursor


Summary by cubic

Fixes a Playwright cookie injection crash and hardens cookie syncing. Adds MCP env vars for cookie reuse, default browser engine, and viewport; disables Playwright video; CLI now runs the MCP server.

  • Bug Fixes

    • Omit sameSite: undefined in cookie payloads to avoid Playwright “Invalid cookie fields”.
    • Fall back to per-cookie injection on batch failure; skip and log invalid cookies.
    • Disable Playwright video recording in MCP mode; remove video handling and output lines.
  • New Features

    • MCP env vars: EXPECT_COOKIES (default cookie reuse, honored even if EXPECT_COOKIE_BROWSERS is empty), EXPECT_BROWSER (default engine), EXPECT_VIEWPORT (e.g. 1280x800).
    • CLI entry now runs the MCP server via @expect/browser/cli (previous TUI/Commander code is commented out).

Written for commit 98dd39e. Summary will update on new commits.

… configuration

- Introduced EXPECT_COOKIES_ENV_NAME and EXPECT_BROWSER_ENV_NAME constants.
- Updated McpSession to utilize new cookie and browser configuration options.
- Enhanced cookie handling logic to support default settings based on environment variables.
- Updated the cookie handling in the Browser class to first attempt batch cookie injection.
- Implemented a fallback mechanism for per-cookie injection in case of batch failures, with detailed logging for skipped cookies.
- Modified the Cookie class to conditionally include the sameSite property in the serialized output.
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
expect Ready Ready Preview, Comment May 6, 2026 7:59am

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 6, 2026

Open in StackBlitz

npm i https://pkg.pr.new/expect-cli@105

commit: 98dd39e

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 7 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/cli/src/index.tsx">

<violation number="1" location="apps/cli/src/index.tsx:1">
P1: This change removes the CLI command parser from the entrypoint, so documented commands like `tui`, `init`, and `watch` are no longer wired here.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Comment thread apps/cli/src/index.tsx
});

program.parse();
import "@expect/browser/cli";
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot May 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: This change removes the CLI command parser from the entrypoint, so documented commands like tui, init, and watch are no longer wired here.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/cli/src/index.tsx, line 1:

<comment>This change removes the CLI command parser from the entrypoint, so documented commands like `tui`, `init`, and `watch` are no longer wired here.</comment>

<file context>
@@ -1,451 +1,456 @@
-});
-
-program.parse();
+import "@expect/browser/cli";
+
+// // HACK: TUI and Commander CLI commented out — entry point now only runs the MCP server.
</file context>
Fix with Cubic

Comment thread packages/browser/src/mcp/mcp-session.ts
Video recording adds unnecessary overhead when running via MCP.
Removes videoOutputDir from createPage and video handling from close.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Added a mechanism to prevent multiple shutdown executions by introducing an `alreadyShutdown` flag.
- Enhanced the `handleShutdown` function to handle errors during session closure and ensure process exit is called only once.
- Registered additional event listeners for `stdin` to trigger shutdown on input end or close.
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/browser/src/mcp/start.ts">

<violation number="1" location="packages/browser/src/mcp/start.ts:22">
P2: The SIGINT/SIGTERM handler no longer exits the process on success. With a signal listener registered, Node won’t terminate automatically, so a successful closeSession will leave the process running.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic.

Comment thread packages/browser/src/mcp/start.ts Outdated
- Introduced viewport option in CreatePageOptions interface.
- Added EXPECT_VIEWPORT_ENV_NAME constant for environment variable configuration.
- Enhanced McpSession to parse and apply viewport settings from the environment variable.
- Updated Browser class to utilize the configured viewport when creating new contexts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant