From bb1c5215a8ef7238be2ef25a17b97ac708ccf994 Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Mon, 14 Sep 2020 13:39:33 +0200 Subject: [PATCH] chore: remove mime dependency (#6415) Bug: #5026, #6125 --- package.json | 1 - src/common/Page.ts | 16 +++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index a97e6309939..a84378c6e73 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,6 @@ "devtools-protocol": "0.0.799653", "extract-zip": "^2.0.0", "https-proxy-agent": "^4.0.0", - "mime": "^2.0.3", "pkg-dir": "^4.2.0", "progress": "^2.0.1", "proxy-from-env": "^1.0.0", diff --git a/src/common/Page.ts b/src/common/Page.ts index d8fcdb1e432..448279722c0 100644 --- a/src/common/Page.ts +++ b/src/common/Page.ts @@ -17,7 +17,6 @@ import * as fs from 'fs'; import { promisify } from 'util'; import { EventEmitter } from './EventEmitter.js'; -import * as mime from 'mime'; import { Connection, CDPSession, @@ -1623,10 +1622,17 @@ export class Page extends EventEmitter { ); screenshotType = options.type; } else if (options.path) { - const mimeType = mime.getType(options.path); - if (mimeType === 'image/png') screenshotType = 'png'; - else if (mimeType === 'image/jpeg') screenshotType = 'jpeg'; - assert(screenshotType, 'Unsupported screenshot mime type: ' + mimeType); + const filePath = options.path; + const extension = filePath + .slice(filePath.lastIndexOf('.') + 1) + .toLowerCase(); + if (extension === 'png') screenshotType = 'png'; + else if (extension === 'jpg' || extension === 'jpeg') + screenshotType = 'jpeg'; + assert( + screenshotType, + `Unsupported screenshot type for extension \`.${extension}\`` + ); } if (!screenshotType) screenshotType = 'png';