getStylesheets
Extract all CSS stylesheets from a webpage to analyze styling, debug layout issues, or collect design assets during browser automation.
Instructions
Get all CSS stylesheets from the current page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/controllers/playwright.ts:346-368 (handler)Core handler function that executes the logic to retrieve stylesheets from the current page using Playwright's page.evaluate, collecting inline styles and external stylesheet URLs.async getStylesheets(): Promise<string[]> { try { if (!this.isInitialized()) { throw new Error('Browser not initialized'); } this.log('Getting page stylesheets'); const stylesheets = await this.state.page?.evaluate(() => { const styleElements = Array.from(document.querySelectorAll('style, link[rel="stylesheet"]')); return styleElements.map(element => { if (element.tagName === 'LINK') { const link = element as HTMLLinkElement; return `/* External stylesheet: ${link.href} */`; } return element.textContent || element.innerHTML; }).filter(content => content.trim().length > 0); }); this.log('Stylesheets retrieved:', stylesheets?.length); return stylesheets || []; } catch (error: any) { console.error('Get stylesheets error:', error); throw new BrowserError('Failed to get stylesheets', 'Check if the page is loaded'); } }
- src/server.ts:133-141 (schema)Tool schema definition specifying name, description, and empty input schema (no parameters required).const GET_STYLESHEETS_TOOL: Tool = { name: "getStylesheets", description: "Get all CSS stylesheets from the current page", inputSchema: { type: "object", properties: {}, required: [] } };
- src/server.ts:714-719 (registration)MCP server request handler case that dispatches the tool call to the Playwright controller's getStylesheets method and formats the response.case 'getStylesheets': { const stylesheets = await playwrightController.getStylesheets(); return { content: [{ type: "text", text: stylesheets.join('\n') }] }; } case 'getMetaTags': {
- src/server.ts:527-527 (registration)Registration of the tool in the tools object passed to MCP server capabilities.getStylesheets: GET_STYLESHEETS_TOOL,