Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Playwright MimeType

From Leeroopedia
Knowledge Sources
Domains MIME Types, File Handling
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for MIME type detection and classification provided by the Playwright library.

Description

The `mimeType.ts` module provides a comprehensive MIME type mapping and utility functions for content type detection. It exports three main functions: `isJsonMimeType` for detecting JSON content types (including `application/json` and various `+json` types), `isTextualMimeType` for detecting text-based content types (including text/*, application/json, application/javascript, application/xml, image/svg+xml, and URL-encoded forms), and `getMimeTypeForPath` for looking up MIME types by file extension. The module contains an extensive static map of file extension to MIME type mappings covering hundreds of common and uncommon file formats including documents, images, audio, video, archives, fonts, 3D models, and application-specific formats. This is an isomorphic module usable in both Node.js and browser environments.

Usage

Use this module when you need to determine the MIME type of a file by its extension, or when checking if a response content type is JSON or textual (e.g., for HAR recording, network interception, or content display).

Code Reference

Source Location

Signature

export function isJsonMimeType(mimeType: string): boolean;
export function isTextualMimeType(mimeType: string): boolean;
export function getMimeTypeForPath(path: string): string | null;

Import

import { isJsonMimeType, isTextualMimeType, getMimeTypeForPath } from '../utils/isomorphic/mimeType';

I/O Contract

Inputs

Name Type Required Description
mimeType string Yes MIME type string to check (for isJsonMimeType, isTextualMimeType)
path string Yes File path to look up MIME type for (for getMimeTypeForPath)

Outputs

Name Type Description
isJson boolean Whether the MIME type represents JSON content
isTextual boolean Whether the MIME type represents textual content
mimeType string or null MIME type for the given file extension, or null if unknown

Usage Examples

import { isJsonMimeType, isTextualMimeType, getMimeTypeForPath } from 'playwright-core/lib/utils/isomorphic/mimeType';

// Check MIME types
isJsonMimeType('application/json');                    // true
isJsonMimeType('application/vnd.api+json');            // true
isTextualMimeType('text/html');                        // true
isTextualMimeType('application/javascript');            // true
isTextualMimeType('image/png');                         // false

// Look up MIME type by file path
getMimeTypeForPath('styles.css');     // 'text/css'
getMimeTypeForPath('script.js');     // 'application/javascript'
getMimeTypeForPath('image.png');     // 'image/png'
getMimeTypeForPath('data.unknown');  // null

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment