mirror of
https://github.com/web-infra-dev/midscene.git
synced 2025-06-26 23:30:04 +00:00
Midscene Chrome DevTools
Chrome extension version of the Midscene tool, providing browser automation, Bridge mode, and a Playground testing environment.
Development Guide
Environment Setup
Make sure you have completed the basic environment setup according to the main project's Contribution Guide.
Directory Structure
chrome-extension/
├── dist/ # Build output directory, can be directly installed as a Chrome extension
├── extension/ # Packaged Chrome extension
│ └── midscene-extension-v{version}.zip # Compressed extension
├── scripts/ # Build and utility scripts
│ └── pack-extension.js # Package Chrome extension
├── src/ # Source code
│ ├── extension/ # Chrome extension-related components
│ │ ├── bridge.tsx # Bridge mode UI
│ │ ├── popup.tsx # Extension popup homepage
│ │ ├── misc.tsx # Auxiliary components
│ │ ├── utils.ts # Utility functions
│ │ ├── common.less # Common style variables
│ │ ├── popup.less # Popup styles
│ │ └── bridge.less # Bridge mode styles
│ ├── blank_polyfill.ts # Browser polyfill for Node.js modules
│ ├── index.tsx # Main entry
│ └── App.tsx # Main application component
├── static/ # Static resources directory, will be copied to the dist directory
│ └── scripts/ # Script resources
│ └── report-template.js # Generated report template
├── package.json # Project configuration
├── rsbuild.config.ts # Rsbuild build configuration
└── ...
Development Process
- Install Dependencies
pnpm install
- Build Dependency Packages
# Build all packages in the project root
pnpm run build
- Development Mode
# Start the project in development mode
cd apps/chrome-extension
pnpm run dev
- Build Project
# Build the Chrome extension
cd apps/chrome-extension
pnpm run build
The build process includes:
- Building the web application using rsbuild
- Generating the report template script (report-template.js)
- Packaging the build artifacts as a Chrome extension
Installing the Extension
Method 1: Using the dist directory (for development and debugging)
The built dist
directory can be directly installed as a Chrome extension:
- Open Chrome browser, navigate to
chrome://extensions/
- Enable "Developer mode" in the top-right corner
- Click "Load unpacked" in the top-left corner
- Select the
apps/chrome-extension/dist
directory
This method is suitable for quick testing during development.
Method 2: Using the packaged extension file
For publishing or sharing:
- Use the
pnpm run build
command to build the project - Find the
midscene-extension-v{version}.zip
file in theextension
directory - Upload this file to the Chrome Web Store developer console, or share it with others for installation
Debugging Tips
Debugging the Extension Background
- Find the Midscene extension on the Chrome extensions page (
chrome://extensions/
) - Click the "view: background page" link to open the developer tools
- Use the console and network panels for debugging
Debugging the Popup Window
- Click the Midscene icon in the Chrome toolbar to open the extension popup
- Right-click on the popup and select "Inspect"
- Use the developer tools to debug UI and interactions
Debugging Content Scripts
- Open any webpage, click the Midscene icon to activate the extension
- Open the developer tools
- Find the Midscene scripts in the "Content scripts" section under the "Sources" panel
Feature Description
Bridge Mode
Bridge mode allows controlling the browser from a local terminal via the Midscene SDK. This is useful for operating the browser through both scripts and manual interaction, or for reusing cookies.
Release Process
- Update the version number in
package.json
to match the main project - Run the build:
pnpm run build
- Verify the
midscene-extension-v{version}.zip
file generated in theextension
directory - Submit the ZIP file to the Chrome Web Store
Troubleshooting
Common Issues
-
Report template generation failure
- Make sure to build the
@midscene/visualizer
package first - Check if
packages/visualizer/dist/report/index.html
exists
- Make sure to build the
-
React Hooks errors
- Check for multiple React instances, might need to adjust the externals configuration in
rsbuild.config.ts
- Check for multiple React instances, might need to adjust the externals configuration in
-
async_hooks module not found
- Check the alias configuration in
rsbuild.config.ts
to ensure it points correctly to the polyfill file
- Check the alias configuration in
-
Extension doesn't work properly after installation
- Check for error messages in the Chrome console
- Verify that the build process was executed completely
- Validate the permissions configuration in the manifest.json file