Skip to content

Conversation

@quanru
Copy link
Collaborator

@quanru quanru commented Dec 31, 2025

No description provided.

@netlify
Copy link

netlify bot commented Dec 31, 2025

Deploy Preview for midscene ready!

Name Link
🔨 Latest commit 7e0050d
🔍 Latest deploy log https://app.netlify.com/projects/midscene/deploys/6964d6188b1291000894372c
😎 Deploy Preview https://deploy-preview-1703--midscene.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@quanru quanru marked this pull request as draft December 31, 2025 09:49
@quanru quanru requested a review from Copilot January 4, 2026 02:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for directory-based report format with local image files, providing an alternative to the traditional single HTML file with embedded base64 images. This is particularly useful for large reports where embedding many base64 images can make the HTML file unwieldy.

Key Changes:

  • Added useDirectoryReport option to agent configuration that generates reports with separate PNG screenshot files instead of embedded base64 data
  • Implemented image extraction to script tags for improved memory performance when parsing large JSON dumps in traditional reports
  • Added frontend support to restore image references from script tags

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/core/src/types.ts Added useDirectoryReport option to AgentOpt interface
packages/core/src/agent/agent.ts Passes useDirectoryReport option to report writing logic
packages/core/src/utils.ts Implements directory report generation, screenshot extraction to files, and image extraction to script tags for traditional reports
apps/report/src/utils/image-restoration.ts New utility to load and restore image references from script tags in the frontend
apps/report/src/App.tsx Integrates image restoration logic when loading dump data
packages/web-integration/tests/ai/web/puppeteer/directory-report.test.ts New test suite validating directory-based report format
packages/web-integration/tests/ai/web/puppeteer/open-new-tab.test.ts Explicitly disables directory report to maintain existing behavior
apps/site/docs/en/api.mdx Documents the new useDirectoryReport option (English)
apps/site/docs/zh/api.mdx Documents the new useDirectoryReport option (Chinese)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 15 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 15 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@quanru quanru marked this pull request as ready for review January 5, 2026 12:35
@quanru quanru requested a review from Copilot January 6, 2026 06:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 42 out of 44 changed files in this pull request and generated 13 comments.

Comments suppressed due to low confidence (1)

packages/core/src/agent/agent.ts:277

  • Potential race condition: The screenshotScale is computed lazily and stored in screenshotScalePromise. If multiple calls to getScreenshotScale happen concurrently before the first one completes, all will create new promises and compute the scale multiple times. The second check on line 259 should happen after the promise settles. Consider using a proper once-only pattern or mutex.
  private async getScreenshotScale(
    rawContext: RawUIContextData,
  ): Promise<number> {
    if (this.screenshotScale !== undefined) {
      return this.screenshotScale;
    }

    if (!this.screenshotScalePromise) {
      this.screenshotScalePromise = (async () => {
        const pageWidth = rawContext.size?.width;
        assert(
          pageWidth && pageWidth > 0,
          `Invalid page width when computing screenshot scale: ${pageWidth}`,
        );

        debug('will get image info of base64');
        const { width: screenshotWidth } = await imageInfoOfBase64(
          rawContext.screenshotBase64,
        );
        debug('image info of base64 done');

        assert(

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const regex =
/<script type="midscene-image" data-id="([^"]+)">([\s\S]*?)<\/script>/g;

for (const match of html.matchAll(regex)) {

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings starting with '<script type="midscene-image" data-id="!">' and with many repetitions of '<script type="midscene-image" data-id="!">a'.

export function parseDumpScript(html: string): string {
const regex = /<script type="midscene_web_dump"[^>]*>([\s\S]*?)<\/script>/;
const match = regex.exec(html);

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings starting with '<script type="midscene_web_dump"' and with many repetitions of '<script type="midscene_web_dump"'.
This
regular expression
that depends on
library input
may run slow on strings starting with '<script type="midscene_web_dump">' and with many repetitions of '<script type="midscene_web_dump">a'.
@quanru quanru force-pushed the feat/local-imgs branch 4 times, most recently from 7f5bcfd to e6d1fd0 Compare January 12, 2026 06:11
quanru and others added 19 commits January 12, 2026 14:12
…er successful write

fix(utils): improve warning messages for screenshot extraction failures
…tItem, streamline image reference restoration
…ot refactoring

Phase 1 of screenshot/dump refactoring RFC implementation:

Storage Layer:
- Add StorageProvider interface for pluggable storage backends
- Implement MemoryStorage for in-memory storage (tests/simple use)
- Implement FileStorage for temp file storage (reduces memory usage)

Core Classes:
- Add ScreenshotItemNew with async getData() for on-demand image loading
- Add ExecutionDumpNew for task execution data management
- Add GroupedActionDumpNew for report serialization/deserialization
- Add image-restoration utilities for Playground/Extension compatibility
- Add HTML parsing/generation utilities for report format

These new classes use 'New' suffix and coexist with legacy classes,
enabling gradual migration in subsequent PRs.
- Use matchAll() instead of while + exec() for safer regex iteration
- Add runtime validation for toJSON() return value in serializeRecorderItem
- Add rollback logic to migrateTo() if deletion from old provider fails
…or navigation in Banner and CTAButtons"

This reverts commit 2f0a86d.
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.

2 participants