|
15 | 15 | * limitations under the License. |
16 | 16 | */ |
17 | 17 |
|
18 | | -import { PNG } from 'pngjs'; |
19 | | -import jpegjs from 'jpeg-js'; |
20 | 18 | import { headersArrayToObject, headersObjectToArray } from '@isomorphic/headers'; |
21 | 19 | import { splitErrorMessage } from '@isomorphic/stackTrace'; |
22 | 20 | import { eventsHelper } from '@utils/eventsHelper'; |
@@ -874,12 +872,9 @@ export class WKPage implements PageDelegate { |
874 | 872 | const omitDeviceScaleFactor = scale === 'css'; |
875 | 873 | this.validateScreenshotDimension(rect.width, omitDeviceScaleFactor); |
876 | 874 | this.validateScreenshotDimension(rect.height, omitDeviceScaleFactor); |
877 | | - const result = await progress.race(this._session.send('Page.snapshotRect', { ...rect, coordinateSystem: documentRect ? 'Page' : 'Viewport', omitDeviceScaleFactor })); |
878 | | - const prefix = 'data:image/png;base64,'; |
879 | | - let buffer: Buffer = Buffer.from(result.dataURL.substr(prefix.length), 'base64'); |
880 | | - if (format === 'jpeg') |
881 | | - buffer = jpegjs.encode(PNG.sync.read(buffer), quality).data; |
882 | | - return buffer; |
| 875 | + const result = await progress.race(this._session.send('Page.snapshotRect', { ...rect, coordinateSystem: documentRect ? 'Page' : 'Viewport', omitDeviceScaleFactor, format: format as 'png' | 'jpeg', quality })); |
| 876 | + // Strip the 'data:image/<format>;base64,' prefix. |
| 877 | + return Buffer.from(result.dataURL.substring(result.dataURL.indexOf(',') + 1), 'base64'); |
883 | 878 | } |
884 | 879 |
|
885 | 880 | async getContentFrame(handle: dom.ElementHandle): Promise<frames.Frame | null> { |
|
0 commit comments