Skip to content

Commit

Permalink
chore: remove mime dependency (#6415)
Browse files Browse the repository at this point in the history
Bug: #5026, #6125
  • Loading branch information
mathiasbynens committed Sep 14, 2020
1 parent 17960e5 commit bb1c521
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -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",
Expand Down
16 changes: 11 additions & 5 deletions src/common/Page.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit bb1c521

Please sign in to comment.