Skip to main content
Glama
code-alchemist01

Development Tools MCP Server

scrape_dynamic_content

Extract JavaScript-rendered content from web pages by simulating browser interaction, enabling developers to access dynamically loaded data for analysis or integration.

Instructions

Scrape JavaScript-rendered content using browser

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL to scrape
waitForSelectorNoCSS selector to wait for
waitForTimeoutNoTimeout in milliseconds
timeoutNoPage load timeout

Implementation Reference

  • Core implementation of the scrape_dynamic_content tool handler using Playwright to scrape dynamic JavaScript-rendered web content, extracting title, text, HTML, links, images, and tables.
    async scrapeDynamicContent(config: ScrapingConfig): Promise<ScrapedData> {
      const validation = Validators.validateScrapingConfig(config);
      if (!validation.valid) {
        throw new Error(`Invalid scraping config: ${validation.errors.join(', ')}`);
      }
    
      const browser = await this.getBrowser();
      const page = await browser.newPage();
    
      try {
        // Set headers if provided
        if (config.headers) {
          await page.setExtraHTTPHeaders(config.headers);
        }
    
        // Navigate to URL
        await page.goto(config.url, {
          waitUntil: 'networkidle',
          timeout: config.timeout || 30000,
        });
    
        // Wait for selector if specified
        if (config.waitForSelector) {
          await page.waitForSelector(config.waitForSelector, {
            timeout: config.waitForTimeout || 10000,
          });
        }
    
        // Wait for additional time if specified
        if (config.waitFor) {
          await page.waitForTimeout(parseInt(config.waitFor) || 1000);
        }
    
        // Extract content
        const title = await page.title();
        const text = await page.evaluate(() => {
          return document.body.innerText.replace(/\s+/g, ' ').trim();
        });
        const html = await page.content();
    
        // Extract links
        const links = await page.evaluate(() => {
          const linkElements = Array.from(document.querySelectorAll('a[href]'));
          return linkElements
            .map((el) => {
              try {
                return new URL((el as HTMLAnchorElement).href).href;
              } catch {
                return null;
              }
            })
            .filter((url): url is string => url !== null);
        });
    
        // Extract images
        const images = await page.evaluate(() => {
          const imgElements = Array.from(document.querySelectorAll('img[src]'));
          return imgElements
            .map((el) => {
              try {
                return new URL((el as HTMLImageElement).src).href;
              } catch {
                return null;
              }
            })
            .filter((url): url is string => url !== null);
        });
    
        // Extract tables
        const tables = await page.evaluate((): TableData[] => {
          const tableElements = Array.from(document.querySelectorAll('table'));
          return tableElements.map((table: Element) => {
            const tableData: TableData = {
              headers: [],
              rows: [],
            };
    
            // Extract caption
            const caption = table.querySelector('caption');
            if (caption) {
              tableData.caption = caption.textContent?.trim() || '';
            }
    
            // Extract headers
            const headerCells = table.querySelectorAll('thead th, thead td, tr:first-child th, tr:first-child td');
            headerCells.forEach((cell: Element) => {
              tableData.headers.push(cell.textContent?.trim() || '');
            });
    
            // Extract rows
            const rows = table.querySelectorAll('tbody tr, tr');
            rows.forEach((row: Element, index: number) => {
              // Skip first row if it's used as headers
              if (index === 0 && tableData.headers.length > 0) {
                return;
              }
              const rowData: string[] = [];
              row.querySelectorAll('td, th').forEach((cell: Element) => {
                rowData.push(cell.textContent?.trim() || '');
              });
              if (rowData.length > 0) {
                tableData.rows.push(rowData);
              }
            });
    
            return tableData;
          });
        });
    
        return {
          url: config.url,
          title,
          text,
          html,
          links: [...new Set(links)],
          images: [...new Set(images)],
          tables,
          scrapedAt: new Date(),
        };
      } finally {
        await page.close();
      }
    }
  • Registration of the 'scrape_dynamic_content' tool within the webScrapingTools array, including its name, description, and input schema.
      name: 'scrape_dynamic_content',
      description: 'Scrape JavaScript-rendered content using browser',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'URL to scrape',
          },
          waitForSelector: {
            type: 'string',
            description: 'CSS selector to wait for',
          },
          waitForTimeout: {
            type: 'number',
            description: 'Timeout in milliseconds',
          },
          timeout: {
            type: 'number',
            description: 'Page load timeout',
            default: 30000,
          },
        },
        required: ['url'],
      },
    },
  • Input schema for the scrape_dynamic_content tool defining the expected parameters: url (required), waitForSelector, waitForTimeout, and timeout.
    inputSchema: {
      type: 'object',
      properties: {
        url: {
          type: 'string',
          description: 'URL to scrape',
        },
        waitForSelector: {
          type: 'string',
          description: 'CSS selector to wait for',
        },
        waitForTimeout: {
          type: 'number',
          description: 'Timeout in milliseconds',
        },
        timeout: {
          type: 'number',
          description: 'Page load timeout',
          default: 30000,
        },
      },
      required: ['url'],
    },
  • Dispatch handler in handleWebScrapingTool function that calls the DynamicScraper instance's scrapeDynamicContent method and formats the output.
    case 'scrape_dynamic_content': {
      const data = await dynamicScraper.scrapeDynamicContent(config);
      return Formatters.formatScrapedData(data);
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'using browser' which implies headless browser automation, but fails to detail critical behaviors like performance impact, resource usage, error handling, or output format. For a tool that likely involves network requests and JavaScript execution, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without unnecessary words. Every part ('scrape', 'JavaScript-rendered content', 'using browser') earns its place by conveying essential information concisely.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of scraping dynamic content (which involves browser automation, potential errors, and varied outputs) and the absence of both annotations and an output schema, the description is incomplete. It doesn't address what the tool returns (e.g., HTML, text, structured data), error conditions, or performance considerations, making it inadequate for safe and effective use by an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all parameters. The description adds no additional semantic context beyond what's in the schema (e.g., it doesn't explain how 'waitForSelector' interacts with JavaScript rendering or typical timeout values). With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate with extra insights.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('scrape') and target ('JavaScript-rendered content'), and specifies the method ('using browser'), which distinguishes it from non-browser scraping tools. However, it doesn't explicitly differentiate from sibling tools like 'scrape_html' or 'scrape_by_selector', which likely handle different content types or methods.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention scenarios like scraping dynamic websites versus static ones, or compare it to sibling tools such as 'scrape_html' or 'scrape_with_interaction', leaving the agent to infer usage based on the name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/code-alchemist01/development-tools-mcp-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server