Skip to content

feat(shell): default Patchright for Playwright via NODE_PATH alias#1266

Open
atxtechbro wants to merge 3 commits intomainfrom
feat/patchright-playwright-default-1263-global
Open

feat(shell): default Patchright for Playwright via NODE_PATH alias#1266
atxtechbro wants to merge 3 commits intomainfrom
feat/patchright-playwright-default-1263-global

Conversation

@atxtechbro
Copy link
Copy Markdown
Owner

  • What: Add NODE_PATH so require('playwright') resolves to Patchright when a user-level alias exists. No wrappers. No per-repo code edits.
  • Why: Undetectable CDP/stealth benefits across all tools (incl. @playwright/mcp). Reduces cognitive load; always-on by default.
  • Scope: One small block in dotfiles/.bash_exports. Alias directory lives outside the repo.
  • Opt-out: unset NODE_PATH or remove ~/.config/node-module-alias.
  • Follow-up (optional): npx patchright install chrome for better stealth.

Closes #1263

@amazon-q-developer
Copy link
Copy Markdown
Contributor

Code review in progress. Analyzing for code quality issues and best practices. Detailed findings will be posted upon completion.

Using Amazon Q Developer for GitHub

Amazon Q Developer1 is an AI-powered assistant that integrates directly into your GitHub workflow, enhancing your development process with intelligent features for code development, review, and transformation.

Slash Commands

Command Description
/q <message> Chat with the agent to ask questions or request revisions
/q review Requests an Amazon Q powered code review
/q help Displays usage information

Features

Agentic Chat
Enables interactive conversation with Amazon Q to ask questions about the pull request or request specific revisions. Use /q <message> in comment threads or the review body to engage with the agent directly.

Code Review
Analyzes pull requests for code quality, potential issues, and security concerns. Provides feedback and suggested fixes. Automatically triggered on new or reopened PRs (can be disabled for AWS registered installations), or manually with /q review slash command in a comment.

Customization

You can create project-specific rules for Amazon Q Developer to follow:

  1. Create a .amazonq/rules folder in your project root.
  2. Add Markdown files in this folder to define rules (e.g., cdk-rules.md).
  3. Write detailed prompts in these files, such as coding standards or best practices.
  4. Amazon Q Developer will automatically use these rules when generating code or providing assistance.

Example rule:

All Amazon S3 buckets must have encryption enabled, enforce SSL, and block public access.
All Amazon DynamoDB Streams tables must have encryption enabled.
All Amazon SNS topics must have encryption enabled and enforce SSL.
All Amazon SNS queues must enforce SSL.

Feedback

To provide feedback on Amazon Q Developer, create an issue in the Amazon Q Developer public repository.

For more detailed information, visit the Amazon Q for GitHub documentation.

Footnotes

  1. Amazon Q Developer uses generative AI. You may need to verify generated code before using it in your environment. See the AWS Responsible AI Policy.

Copy link
Copy Markdown
Contributor

@amazon-q-developer amazon-q-developer bot left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! I have reviewed the changes to implement Patchright as the default backend for Playwright. While the implementation is clever, there are several concerns to address:

  1. Security: The global NODE_PATH modification approach poses potential security risks through untrusted search paths.
  2. Robustness: There are opportunities to improve the shell script's robustness through better parameter expansion and path handling.
  3. Syntax: There's an unnecessary escape character that should be removed.

Consider exploring alternative approaches like npm's package aliasing or project-level configurations that don't require global NODE_PATH modifications. This would provide similar functionality while maintaining better security practices.

Comment on lines +35 to +36
export PATCHRIGHT_MODULE_ROOT="$HOME/.config/node-module-alias/node_modules"
if [ -d "$PATCHRIGHT_MODULE_ROOT" ]; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛑 [Security Risk]: Modifying NODE_PATH globally to inject modules can pose security risks1. Consider using project-level configurations or npm's package aliasing instead. This approach could lead to unintended module resolution and potential supply chain attacks.

Footnotes

  1. CWE-426: Untrusted Search Path - https://cwe.mitre.org/data/definitions/426.html

# If a user-level module alias exists at ~/.config/node-module-alias/node_modules,
# add it to NODE_PATH so that require('playwright') resolves to Patchright.
# This avoids wrapper scripts and per-repo code changes.
export PATCHRIGHT_MODULE_ROOT="$HOME/.config/node-module-alias/node_modules"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider using ${HOME} instead of $HOME for consistent shell parameter expansion and to prevent potential word splitting issues. Also, consider quoting the path to handle spaces in directory names.

Comment on lines +38 to +39
*:$PATCHRIGHT_MODULE_ROOT:*) ;;
*) export NODE_PATH="$PATCHRIGHT_MODULE_ROOT:${NODE_PATH}" ;;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider handling the case where NODE_PATH is unset. The current approach might result in a trailing colon when NODE_PATH is empty. A more robust approach would be to use parameter expansion with default values.

Suggested change
*:$PATCHRIGHT_MODULE_ROOT:*) ;;
*) export NODE_PATH="$PATCHRIGHT_MODULE_ROOT:${NODE_PATH}" ;;
*) export NODE_PATH="${PATCHRIGHT_MODULE_ROOT}${NODE_PATH:+:${NODE_PATH}}" ;;

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.

Default Patchright backend for Playwright MCP (keep @playwright/mcp)

1 participant